Write a program to accept details of n students (roll number, name, percentage) and write it to a file named “student.txt”. Accept roll number from the user and search the student in the file.
Anonymous:
___k off
Answers
Answered by
5
#include <stdio.h>
int main() {
char name[50];
int roll[50];
int marks,i,j,n;
printf("Enter number of students: ");
scanf("%d",&n);
FILE *fptr;
fptr=(fopen("C:\\student.txt","w"));
if(fptr==NULL) {
printf("Error!");
exit(1);
}
for (i=0;i<n;++i) {
printf("For student%d\nEnter name: ",i+1);
scanf("%s",name);
printf(For student%d\nEnter roll: ",j+1);
scanf("%s",roll);
printf("Enter marks: ");
scanf("%d",&marks);
fprintf(fptr,"\nName: %s \nMarks=%d \n",name, roll,marks);
}
fclose(fptr);
return 0;
}
Similar questions
Social Sciences,
6 months ago
Accountancy,
6 months ago
Science,
1 year ago
Biology,
1 year ago
Physics,
1 year ago