Coding for file handling. I cannot find the .txt file on my desktop. I am using MAC OS
void upload(){
FILE *fp;
int i;
fp = fopen("StudentRecord.txt","w+");
if (fp==NULL){
printf("File Error!\n");
system("pause");
}
else {
for (i=0;i<=L.last;i++)
fprintf(fp,"%s %d %d %d\n",L.st[i].name,L.st[i].q1,L.st[i].q2,L.st[i].q3);
}
fclose(fp);
}
void download(){
FILE *fp;
REC x;
fp = fopen("StudentRecord.txt","r+");
if (fp==NULL){
printf("File error!\n");
system("pause");
}
else{
while(!feof(fp)){
fscanf(fp,"%s %d %d %d \n",x.name,&x.q1,&x.q2,&x.q3);
add(x);
}
fclose(fp);
}
}
File extension .txt should be available in the folder where my main.c is located.