Well, yes it prints all 15, but ten on one line and five on another.
Well, yes it prints all 15, but ten on one line and five on another.
Not with that code. Still all 15 on one line...
outputsCode:.... int s; for (s = 0; s < numberOfChar; s++) { int a = 0; fscanf(fp, "%d", &x[s]); printf("%d ", x[s]); if (a ==10) { printf("\n"); a++; } } ....
Code:475 3260 7102 6004 8467 7024 1819 2901 3844 3613 640 7549 3096 3365 771 Press any key to continue...
Last edited by fmsguy06; 11-09-2008 at 04:44 PM.
Well, now you moved your a++ into the if statement where it doesn't belong. a++ needs to always happen, regardless of whether we're at 10 or not.
Nor does it work before the if or after the if.
outputs:Code:int s; for (s = 0; s < numberOfChar; s++) { int a = 0; fscanf(fp, "%d", &x[s]); printf("%d ", x[s]); a++; if (a ==10) { printf("\n"); } }
Code:475 3260 7102 6004 8467 7024 1819 2901 3844 3613 640 7549 3096 3365 771
as does
return the same.Code:for (s = 0; s < numberOfChar; s++) { int a = 0; fscanf(fp, "%d", &x[s]); printf("%d ", x[s]); if (a ==10) { printf("\n"); } a++; }
Ah -- now I see. The int a = 0 is inside the brace, which means it gets reset to 0 every time through the loop.
You are correct. Placing the definition of a outside the brace, made it work, up to 20.
Adding a line to make a = 0 after the print of the newline allowed it to work for over 20 numbers as well. Great. It does what I was interested in doing and some now. Now just trying to get it to display an error if the file to read from is not found (as right now it just freezes and quits the compiler). I thank you all for helping me get this far though!Code:int s; int a = 1; for (s = 0; s < numberOfChar; s++) { fscanf(fp, "%d", &x[s]); printf("%d ", x[s]); if (a ==10) { printf("\n"); } a++; }