Novicane All American 15416 Posts user info edit post |
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);
is what i got.1/31/2008 9:30:59 AM |
dakota_man All American 26584 Posts user info edit post |
how is num[] defined?
if it's just ints or something you can't just assign s to it
EDIT:
just use fscanf instead of fgets
http://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 |
Novicane All American 15416 Posts user info edit post |
int num[10]; //im assuming this means an array of 10 integers. int s; //integer 1/31/2008 9:56:03 AM |
dakota_man All American 26584 Posts user info edit post |
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 |
Novicane All American 15416 Posts user info edit post |
ah! thats it. 1/31/2008 10:18:25 AM |