Originally Posted by
mbr123
I use fopen to open the text file
and I want to read every 2number for a loop, and read next set of 2number for 2nd loop, How Can I do that?
You can't.... not and have it work reliably. As I already pointed out fseek() is totally unreliable in text files it is intended for fixed size records, not variable length lines.
Why don't you read them into two arrays in one loop... something like this...
Code:
int EvenLines[MaxLines/2] = {0};
int OddLines[MaxLines/2] = {0};
int idx = 0;
FILE f = fopen("textfile","r")
while ((!eof(f)) && (idx < MaxLines/2)))
{ fscanf("%d",EvenLines[idx]);
fscanf(%d",OddLines[idx]);
idx++; }
Now you have two separate arrays one with lines 0, 2, 4, etc the other with lines 1, 3, 5, etc.
Or you could just read them all into one array and access them by odd and even indexes.
@adak... you're faster... mines better