I read in this txt file of 10 numbers. When I go to print the numbers I read in from the array, they don't print. Then when I refer to specific index's within the array nothing prints. how can I store these numbers into an array?
f=fopen("numbers.txt","r"); if (!f) return 1; while (fgets(s,1000,f)!=NULL){ count++; printf("%s",s); num[count]=s; } fclose(f);
1/31/2008 9:30:59 AM
how is num[] defined?if it's just ints or something you can't just assign s to itEDIT:just use fscanf instead of fgetshttp://www.cplusplus.com/reference/clibrary/cstdio/fscanf.html[Edited on January 31, 2008 at 9:47 AM. Reason : .]
1/31/2008 9:40:52 AM
int num[10]; //im assuming this means an array of 10 integers.int s; //integer
1/31/2008 9:56:03 AM
well, I think fgets gives you characters, not ints. Also, printf("%s",s); is trying to print a string, not an int. If s was an int, you'd want to use %d instead.
1/31/2008 10:11:27 AM
ah! thats it.
1/31/2008 10:18:25 AM