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

By | 01.12.2016

Read student details and store it in file


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 .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

3.3 8 votes
Article Rating
Category: C Programming File Handling Tags:

About Tunde A

My name is Tunde Ajetomobi, a Tech Enthusiast and Growth Hacker. I enjoy creating helpful content that solves problem across different topics. Codezclub is my way of helping young aspiring programmers and students to hone their skills and find solutions on fundamental programming languages.

Subscribe
Notify of
guest

4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ketharin

Can u pls tell me the file patha which u have given..i have confusion on what file path should be given..

parth

that path will be where u want to store your file

Royal

I RUN THE SAME PROGRAM BUT THEY SHOW MW ERROR TO DECLARATION IS NOT ALLOWED HERE.THE LINE IS “FILE *fptr”

Maxx

Hii
H