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: ");
scanf("%s", students[i].name);
printf("Enter address: ");
scanf("%s", students[i].address);
printf("Enter age: ");
scanf("%d", &students[i].age);
}
fwrite(students, sizeof(struct Student), count, fp);
fclose(fp);
printf("Data written to file successfully! ");
return 0;
}
(b) To edit the file created in (a) to add data for 2 more students:
#include <stdio.h> #include <stdlib.h> #define MAX_STUDENTS 10 struct Student { _________ ________ _____ _________ ____ __________.
_________ ______ ____ _________ ___ __________.
______ ___ _____ _________ _______ ___.
___ ____ ____ ________ ________ _______ _______ ________ _______.
_____ __________ _____ _____ _________ _____ _______ ____ __________.
________ _________ ______ ___ ________.
____ _______ ________ _________ ______ ____ ________ ________ ________.
____ _________ _____ ___ _______ __________ ________ _______ ______.
_______ _______ __________ ______ ________ ___ _________ ____ ________ ___ _______.
______ _______ _____ ________ _________ ______ ________ __________.
__________ ______ _____ ____ ____ ____ _____ __________ ______.
___ _______ _____ ________ ________ _________.
_____ _______ ____ __________ _______.
_________ _______ _______ _______ _____ ______.
___ ________ ________ ________ ________ ____ ________ ________ ________.
___ ______ _______ ___ _____ ____ ___ ______ _________.
____ _________ _______ ____ ____ ______ ____.
______ _______ ____ ___ ________ _________ ________ __________ ___.
______ ______ _______ ______ __________ ____ ____ ___ ___ __________ _________ _________.
_________ ___ ________ _____ ____ ____ _________ ______ __________.
___ _______ ____ _______ _______ _________.
____ _____ _________ _____ ___ ______ _________ _______ _________ ______ ____.
______ __________ ________ ____ _____ ______ ____ ______ ________ _________ __________.
_______ ______ ____ __________ _____.
________ _____ _____ ___ __________.
____ ________ _________ ____ ______ _______.
_________ ___ _________ _______ ____ ___ ________.
_________ ________ _____ ___ __________ ___ _________ _________ _________.
_________ ______ ___ ____ _____ ____ ______ ___ _____ ___.
_________ __________ _________ _________ ____ __________ ____ ____ ____.
_________ _______ _______ ___ ________ _____ ___ ___.
______ _______ ____ _________ _____ __________.
_____ ____ ______ _________ _______ _______ ________.
________ ________ __________ _____ ______ ______ _________ _________ ________ _____ ________.
_________ _______ __________ ___ _________ ______ _______ ___ ____.
______ ___ __________ _______ ____ _______.
______ ___ ____ ______ ____ ________ _____ ________ _______ ____ ___.
______ ____ ___ ___ _________ ___ ___ _______ _________ __________.
_________ ____ ____ _______ ________ ________ ______ __________ ________ ______ _________ ________.
_______ ___ ______ ____ _________ ____ __________ ________ ________ __________ __________ ______.
_____ __________ __________ _______ ________ ______ ________ _____ ___ ___ ______.
______ __________ ______ ______ _______ ________ _______.
_______ _____ ____ ___ _______ ________ ________.
___ ______ _________ ________ _______ ___ __________ _______ ________.
______ ______ ______ ______ ____.
______ ______ _________ ___ _______ ___ _______.
_________ ________ _____ __________ _____ ___ ________ ________ ____ ___.
__________ _____ ______ _________ _____ ___ ___ ______ ________ ______ ____ ___.
_________ _____ __________ _____ _______ ______ _________ _______.
_______ ________ ______ ___ _______.
________ _______ ______ _____ ____ ______ ________ _________ _______ _______.
_____ ______ ______ __________ _______ _______.
____ ________ ______ __________ __________ _______ ____ ________ ________ ______.
_____ __________ ________ ____ _________ _________ ____ ___ _________ __________ ______.
____ ______ ____ ___ _____ ____ ___ __________.
__________ _______ ______ ____ ________ ______ ___ _____ ______ _______.
_________ __________ ____ __________ __________ ______ _____ _________ __________ ______.
__________ _______ ________ ____ ________ ______ _____.
____ ________ ______ _______ ________ __________ ________ ______.
_______ ___ _______ ____ ____ ______ _______ ______ _______ ___ ___.
_______ ___ _________ __________ ___.
______ ___ _______ __________ _________ __________ __________ ______ __________ ________ _____ _____.
_____ ____ _______ _________ ___ __________ _________ ____ __________ ___ _________.
___ _________ _______ _________ ___ __________ ________ _________ ______ __________ ___.
____ _____ __________ _________ ____ ____.
_________ ____.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
✓ Unlock up to 60% of the answer
✓ No payment required