-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathappend.c
37 lines (35 loc) · 879 Bytes
/
append.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
//program to append records to a file
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
struct record
{
char name[20];
int roll;
int marks;
} student;
FILE *fp;
int choice = 1;
fp = fopen("stu", "ab"); //append in append mode
if (fp == NULL)
{
printf("Error in openning file\n");
exit(1);
}
/*//program to append records to a file*/
while (choice == 1)
{
printf("Enter name: ");
scanf("%s", student.name);
printf("Enter roll no : ");
scanf("%d", &student.roll);
printf("Enter marks: ");
scanf("%d", &student.marks);
fwrite(&student, sizeof(student), 1, fp);
printf("Want to enter more ?(1 for yes/ 0 for no) : ");
scanf("%d", &choice);
}
fclose(fp);
return 0;
}