
March 20th, 2010, 03:42 AM
|
|
Registered User
|
|
Join Date: Mar 2010
Posts: 1
Time spent in forums: 16 m 9 sec
Reputation Power: 0
|
|
|
C Programming: Text File I/O
Hi! I'm relatively new at programming so I'm having a bit of a problem.
My first question is, how do I print out long strings with spaces from a text file? I tried printing it out the normal way but only the first word gets printed out. My professor required us to print out bible passages from a text file.
For my second question, I have this code:
Code:
fp=fopen("Score.txt", "r");
for(i=0;i<30;i++){
fscanf(fp,"%s\n%s\n\n",scorename[i],scorescore[i]);
printf("%s\n%s\n\n",scorename[i],scorescore[i]);
}
It's supposed to print out the scores stored in Score.txt. But say, I have only one score recorded. It prints out 29 junk data for the rest. I'm planning on replacing 30 with n so that it will print only the correct number of scores. But my problem is, how can I keep track of the number of scores inside the text file? I need to retain this even when restarting the program.
|