Hey all, back again with another post. This time its arrays!
I've gotten basic arrays down and working and at the moment am trying to make something a little more complicated (for me at least).
I have a data.txt file in the same folder as my array.c file which has a load of values set out in 4 columns
Ie
77, 66, 80, 81
40, 5, 35, -1
51, 58, 62, 34
0, -1, 21, 18
61, 69, 58, 49
81, 82, 90, 76
44, 51, 60, -1
64, 63, 60, 66
-1, 38, 41, 50
69, 80, 72, 75
I have to write some code such that my program reads these values and stores them in an array using the unix command ./array < data.txt. Its meant to do some calculations based on the values in data.txt, however at the moment I am doing a simple printf to check if the array storage works.
At the moment I have the following
Running this prints the correct value for mark[0] and the wrong values for mark[4] and mark[8]. This suggests to me my for statement is messed up somehow, but I'm not seeing how. If anyone could show me whats going wrong it would be much apprecaited.Code:#include <stdio.h> int main() { int mark[40], i; /*setting up array and i as ints*/ for(i = 0; i < 40; i++) /*for i=0, i<40 increase i by 1*/ { scanf("%d",&mark[i]); /*scan for value to store in array*/ } printf("%d\n", mark[0]); /*testing arrays via printing*/ printf("%d\n", mark[4]); printf("%d\n", mark[8]); }
Advance thanks,
Native



LinkBack URL
About LinkBacks


