-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew_File.c
More file actions
37 lines (33 loc) · 939 Bytes
/
Copy pathNew_File.c
File metadata and controls
37 lines (33 loc) · 939 Bytes
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
#include <Stdio.h>
struct Register {
char name[100];
int RNo;
char city[100];
};
void main(){
struct Register s[100];
int count = 0;
char choice;
do{
printf("Enter details of student %d\n", count+1);
printf("Name: ");
scanf("%s",s[count].name);
printf("Roll.No: ");
scanf("%d",&s[count].RNo);
printf("City: ");
scanf("%s",s[count].city);
count++;
printf("\nDo you want to add another student? (y/n): ");
scanf(" %c", &choice);
}
while (choice == 'y' || choice == 'Y');
FILE *fptr;
fptr = fopen("First.txt","w");
for (int i = 0; i < count; i++) {
fprintf(fptr, "\nStudent %d:\n", i + 1);
fprintf(fptr, "Name : %s\n", s[i].name);
fprintf(fptr, "Roll.No : %d\n", s[i].RNo);
fprintf(fptr, "City: %s\n", s[i].city);
}
fclose(fptr);
}