Read and Write student records to a file
Write a C program to Read and Write student records to a file. Here’s simple program to Read and Write student records to a file in C Programming Language.
Below is the source code for C program to Read and Write student records to a file which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C program to Read and Write student records to a file */ #include<stdio.h> #include<conio.h> #include<stdlib.h> struct student { int rollno; char name[50]; int m1,m2,m3; }s1; int main() { FILE *fp; fp=fopen("C:\\Users\\acer\\Documents\\file4.txt","w"); if(fp==NULL) { printf("File could not open"); exit(0); } printf("Enter student details :: \n"); printf("\nName :: "); scanf("%s",&s1.name); printf("Roll No :: "); scanf("%d",&s1.rollno); printf("Marks1 :: "); scanf("%d",&s1.m1); printf("Marks2 :: "); scanf("%d",&s1.m2); printf("Marks3 :: "); scanf("%d",&s1.m3); fwrite(&s1,sizeof(s1),1,fp); printf("\nRecord has been added successfully !!\n"); fclose(fp); return 0; }
OUTPUT : :
/* C program to Read and Write student record to a file */ Enter student details :: Name :: CodezClub Roll No :: 1331 Marks1 :: 87 Marks2 :: 89 Marks3 :: 95 Record has been added successfully !! Process returned 0
Above is the source code for C program to Read and Write student records to a file 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….
The numbers are not showing
i have very use your website,thanking you