-
Notifications
You must be signed in to change notification settings - Fork 4
/
modify.c
48 lines (45 loc) · 1.21 KB
/
modify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//program to modify the record in a file
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
struct record
{
char name[20];
int roll;
int marks;
} student;
FILE *fp;
char name[20];
long size = sizeof(student);
unsigned flag = 0;
fp = fopen("stu", "rb+");
if (fp == NULL)
{
printf("Error in openning file\n");
exit(1);
}
printf("Enter the name of student whose record is to be modified : ");
scanf("%s", name);
while (fread(&student, sizeof(student), 1, fp) == 1)
if (strcmp(student.name, name) == 0)
{
printf("Enter new date -->\n");
printf("Enter name : ");
scanf("%s", student.name);
printf("Enter roll no : ");
scanf("%d", &student.roll);
printf("Enter marks: ");
scanf("%d", &student.marks);
fseek(fp, -size, 1);
fwrite(&student, sizeof(student), 1, fp);
flag = 1;
break;
}
if (flag == 0)
printf("Name not found in file\n");
else
printf("Record Modified........\n");
fclose(fp);
return 0;
}