Alright, i've got a problem! my program reads a text file that has x and y co-ordinates for a number of points on a graph, i can read the file ok, but need to find the max and min values for x and y thats where it goes wrong!
this is what i'e got:
i cann't get it to scan through all the coordinates correctly. any help appreciated!
int length =0;
int i =0;
if ((stream = fopen("Points.txt","r")) == NULL)
fprintf(stderr,"Error opening file.");
if (sscanf(buf,"%d %d", &a,&b))
pointX[i] = a;
pointY[i] = b;
Max_X = pointX;
Min_X = pointX;
Min_Y = pointY;
Max_Y = pointY;
if(Max_X < pointX[v] ) Max_X = pointX[v];
if(Min_X > pointX[v] ) Min_X = pointX[v];
if(Max_Y < pointY[v] ) Max_Y = pointY[v];
if(Min_Y > pointY[v] ) Min_Y = pointY[v];
It seems ok. How do you declare pointX and pointY? Perhaps your indexes are wrong (an array with n elements range from 0 to n-1)?
declared like this:
when i compile the max values have some random number in them and te min values are always 0,
As always, the error is right in front of the nose ;).
for(v = 2; v = 35266; v++)
(Why start at 2? That's the third element)
for(v = 2; v < 35266; v++)
If that wasn't the problem, perhaps you're compiling in a 16-bit compiler? Integers then range from ~ -32000 to +32000, making it impossible to address 35266.