-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1_student_info_storage.c
More file actions
61 lines (50 loc) · 1.11 KB
/
1_student_info_storage.c
File metadata and controls
61 lines (50 loc) · 1.11 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
//write a C program for Student information storage and retrieval using file handling.
#include<stdio.h>
#define SIZE 1024
int main()
{
char text[SIZE] = {0},record[100];
char ch;
int cnt=0,len;
FILE *fp;
fp = fopen("file1.txt", "w");
if(fp==NULL)
{
printf("Error in creating file");
return -1;
}
printf("\nEnter student details line wise (Press # to save and close): \n");
printf("Enter in format NAME - AGE - TOTAL MARKS \n");
while(1)
{
ch=getchar();
if(ch=='#')
{
break;
}
fputc(ch,fp);
}
fclose(fp);
printf("File saved successfully\n");
fp=fopen("file1.txt", "r");
if(fp==NULL)
{
printf("Error in opening file.\n");
return -1;
}
printf("Entered records are: \n");
cnt=0;
while((ch=fgetc(fp))!=EOF)
{
if(ch==0x0A)
{
record[cnt++]='\0';
cnt=0;
printf("%s\n", record);
continue;
}
record[cnt++]=ch;
}
fclose(fp);
return 0;
}