All articles
c

A program to create student FILE

Share this article

Share on LinkedIn Share on X (formerly Twitter)

C Programming Language 117

  • Write a program to create student FILE

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'

Comments