Q:

Write a C program to Read and Write student records to a file

0

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.

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

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
C program read integers and appends sum to the end... >>
<< Write a C Program to append data into a file using...