i want write a program that get name,familyname,student number of ten people
and then store in a file(students.txt)
and then with a new function read that file and save in stucture with these
field name,fname,student_no
and finally with another function sort studnet_no and save in sortedstudents.txt file
i do not know how can i link these function
can someone help me?
Code:#include <stdio.h> int main() { FILE *f; char name[10][10],fname[10][10]; int student_no[10]; f=fopen("students.txt","w+"); for (int i=0 ; i<10 ; i++) { printf("\nEnter Name Of Student %d:",i+1); scanf("%s",name[i]); printf("Enter Family Name of Student %d:",i+1); scanf("%s",fname[i]); printf("Enter Student Number Of Student %d:",i+1); scanf("%ld",&student_no); } fprintf(f,"name fname student_no\n"); fprintf(f,"----- ----- ----\n"); for (i=0 ; i<10 ; i++) fprintf(f,"%s %s %ld\n",name[i],fname[i],student_no[i]); fclose(f); return 0; } // store in structure function struct studentinfo{ char name[20]; char fname[20]; int student_no[10]; }student[10]; void main() { FILE *f; int k; p=fopen("student.txt","rb"); fread(student,sizeof student,1,p); for(k=0 ; k<10 ; k++) { printf("%s",student[k].name); printf("%s",student[k].fname); printf("%s",student[k].student_no); } fclose(p); }



LinkBack URL
About LinkBacks



