Home

A program to create student FILE

C Programming Language 117

Program

#include <stdio.h>
#include <stdlib.h>

void main()
{
    int c;
    FILE *fp;

    fp = fopen("student.txt", "w");
    if (fp == NULL)
    {
        printf("Error: unable to create student.txt\n");
        exit(1);
    }

    printf("Type the content to store in student.txt ... (Press CTRL+D to trigger EOF)\n\n");
    while ((c = getchar()) != EOF)
    {
        putc(c, fp);
    }
    fclose(fp);

    printf("\n");
}

Result

Type the content to store in student.txt ... (Press CTRL+D to trigger EOF)

Alice 123 'A'


Last Updated on

Next Post: GraphProtocol: TS2322 null assignment in Subgraph →

Comments