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.
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 .
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 : :
OUTPUT : :
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