Q:

Write a C Program to read student details and store it in file

0

Write a C Program to read student details and store it in file using File Handling. Here’s simple Program to read student details and store it in file using File Handling in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Below is the source code for C Program to read student details and store it in file using File Handling which is successfully compiled and run on Windows System to produce desired output as shown below :

 
 


SOURCE CODE : :

/*  C Program to read student details and store it in file using File Handling  */

#include<stdio.h>
#include<stdlib.h>
int main()
{
        char name[50];
        int marks,i,n;
        printf("Enter number of students: ");
        scanf("%d",&n);
        FILE *fptr;
        fptr=(fopen("C:\\Users\\acer\\Documents\\student.txt","w"));
        if(fptr==NULL) {
                printf("\nError!");
                exit(1);
        }
        for (i=0;i<n;++i) {
                printf("\nFor student%d\nEnter name: ",i+1);
                scanf("%s",name);
                printf("Enter marks: ");
                scanf("%d",&marks);
                fprintf(fptr,"\nName: %s \nMarks=%d \n",name,marks);
        }
        fclose(fptr);
        return 0;
}

OUTPUT : :


/*  C Program to read student details and store it in file using File Handling  */

Enter number of students: 4

For student1
Enter name: codez
Enter marks: 66

For student2
Enter name: club
Enter marks: 88

For student3
Enter name: john
Enter marks: 99

For student4
Enter name: max
Enter marks: 55

Process returned 0

Above is the source code for C Program to read student details and store it in file using File Handling which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C Program To read text file and print it o... >>
<< Write a C program to Merge two files using file ha...