Using File Handling concept in C programming, write the C programs for the following:
(a) To create and store student information of 10 MCA students in a .dat file.
(b) To edit the file created in (a) to add data for 2 more students.
(c) To delete specific line(one student record) from a file.
(a) To create and store student information of 10 MCA students in a .dat file:
#include <stdio.h>
#include <stdlib.h>
#define MAX_STUDENTS 10
struct Student {
int roll_number;
char name[50];
char address[100];
int age;
};
int main() {
struct Student students[MAX_STUDENTS];
int count;
FILE *fp;
fp = fopen("students.dat", "wb");
if (fp == NULL) {
printf("Error opening file! ");
exit(1);
}
printf("Enter the number of MCA students: ");
scanf("%d", &count);
for (int i = 0; i < count; i++) {
printf("Enter details of student %d ", i + 1);
printf("Enter roll number: ");
scanf("%d", &students[i].roll_number);
printf("Enter name: ________ _________ _________ __________ __________ ___ ________ ______ _____ _____ _____ _________.
_____ __________ _____ _______ _______ ________.
_______ __________ __________ ______ _______.
_______ ____ ________ ________ ________ _____ _____ _______ ______ ______ ________.
_____ ________ ___ __________ _____.
_____ ___ _______ _________ ________ __________ _____ ___ ______ _____ __________.
_______ ______ __________ _____ _________ _______ __________.
_________ ______ ______ __________ _______ ____ ___ _____ ____.
____ ________ __________ _____ _________ _____ ____ ___ _____ ____.
___ _________ ___ _________ ___ _______ ___.
______ ________ ____ ____ _____.
__________ ___ ______ ________ ___.
_______ ____ ______ ____ __________ _________ ______.
_____ _____ _____ ___ ______ ___ __________ ______ __________ ______ ________ _____.
_______ ______ _______ _______ _________ _________.
__________ ___ ________ _________ _________ ________ ________ ___ ___ ________ ____.
____ ____ ______ ____ _________ ______ ______.
_________ ___ _____ ________ __________ __________ _____ _________ ____.
________ ______ _________ ____ _____ _______.
_________ ____ ____ ________ ________ _____ ____ ________.
_____ ______ ______ _____ _______ _____ _____ _____ _________ ___ ________ _________.
________ _____ _______ ___ ____ ________ ______ ______ _____ _________ _________.
______ _____ _________ _______ _______.
______ _____ _________ __________ ____ ___.
___ ____ _____ ______ _________ _________ ______.
________ ___ _________ ________ ____ ____.
_____ __________ ____ ____ ________ ______ _______.
_______ ______ _________ ___ ________ ______.
_________ ______ ___ __________ __________ __________ _______ ________ __________.
________ ___ ________ _______ ____ _______ ______ ___ ________ ________ ______.
_____ ___ ________ _____ _________ ___ _____.
_______ ___ _________ ______ _________ _________ ________ __________ _______ _____ ________.
_______ _________ __________ _____ __________ ____ __________ ____.
________ _______ __________ ____ _________ ______ ________ _____ _____ _______ __________.
__________ ___ _________ ________ ________ ______ ___ _____ __________.
___ ______ ________ _______ ____ ___ ________ ______.
______ ______ ______ _______ ________ ______ _______ ________ __________ ___ ____.
___ __________ ___ ______ ________ ____ ___ _____ _____ ______.
_____ __________ __________ _________ ____ _________ __________ _____ ____ ______ __________ ________.
__________ ________ _______ ________ ____ ____ ______ ____ ____ __________ __________ ________.
____ __________ _____ _____ _________ __________ ______ ________ __________ _____.
_______ _____ ____ ____ ____ _______.
__________ ______ ______ _____ ___ __________.
_____ _________ _________ ______ ____ ______ ______.
________ __________ ____ _____ __________ ___.
_____ ______ ________ __________ ______ _________ _____ _____ _____ _________ _________ ____.
_________ ____ ________ _________ ___ _______ _______ __________ ___.
________ ___ ______ __________ ______ __________ _______.
______ ___ ______ ________ ___ _____ _______ ____ _________ ___ __________ __________.
____ ____ _________ __________ _____ ______.
__________ ___ _____ ____ _____ _________ _________ ____ _______ ____ ________ __________.
_________ __________ ____ __________ _______.
___ _______ ________ ____ ___ _______ _________ _________.
____ ____ __________ ________ _______.
____ _______ _____ ______ ___ ______ _____ _____ _______ _______.
___ ___ ____ ________ _________ __________.
_____ ____ __________ ________ ____ ___ ________ _____ _________ _________ _________.
______ _____ _______ _________ ______ _____ _________.
__________ _____ ________ _____ _______ ________ ____ ________.
_____ _____ _______ __________ ___ ______ _____ _________ ________ ___ _____.
____ _____ ______ __________ _____ ____ ____ ______ _______ ____ _________ ________.
___ ________ ___ __________ ________ ____ _______ _________ _______ ____ ________.
___ _____ _____ _____ ____ __________ ______ ________ ___ ___.
____ ___ ________ ______ __________ ____ ____ _________.
_______ ______ _____ __________ ______ _________ ___ ________ ___ ___.
___ _____ _________ _____ ______ ___ __________ ____ __________ ____ ______ _________.
_________ ________ _____ _______ _________ ___ ______ ____.
_____ _________ __________ _________ __________.
__________ __________ ________ _________ ________ ____ ___.
_____ ______ _______ ____ ________ _________ __________ _______ ____.
____ _________ ________ __________ ___ ______.
___ ______ _______ _____ _________ _________ __________ _____ _________ ____ ____ ____.
_______ ________ __________ ____ __________ _________ ________.
______ ____ _____ _____ ____ ______ ______ _____ __________.
__________ ___ _______ ______ __________ _________ _______ _________ ___.
_____ ________ _______ _______ ____ ____ ___ ___.
______ __________ _______ _______ ________.
__________ _____ __________ ________ ____ ___.
Get Full Answer on WhatsApp