OK not sure why it is reposting my messages, checked all settings and seem fine?
Anyway I have worked quite a bit on my code overnight and have got 90% of it working, just wanted to ask some help on data being stored in a file and then retrieved.
These are my two functions for adding a record, and listing records:
[tag]
Code:
void Add(void){
char opt;
fp=fopen("Records2.txt","a");
printf("\nAdd Record");
printf("\nStudent Name:"); scanf(" "); gets(record.Name);
printf("\nStudent Number:");scanf(" "); gets(record.Number);
printf("\nStudent Grade:");scanf(" "); gets(record.Grade);
fprintf(fp,"%s %s %s ",record.Name,record.Number,record.Grade);
printf("Press any key to go to main menu...");
getch();
fclose(fp);
}
[tag]
[tag]
Code:
void List(void){
int count=0,i, x=0;
fp=fopen("Records2.txt","r");
printf("Name Number Grade\n\n");
for(i=1;i<1;i++){ ;puts("Í");}
while(fscanf(fp,"%s %s %s",&record.Name,&record.Number,&record.Grade)!=EOF){
if(count!=0&&count%5==0){ printf("Press any key to continue..."); getch(); x=0;
for(i=10;i<=24;i++);}
}
printf("%s %s %s",record.Name,record.Number,record.Grade);
x++;
count++;
printf("\nPress any key to go to main menu...");
getch();
fclose(fp);
}
[/tag]
These all compile and work to a degree but when I run my program, only the last record is shown on the screen and not all the records stored in the text file. Any hints or help on this?
I do not think I am a million miles away..
Thanks In Advance!