hi all
problem is.. i need 2 extract certain data fields from a text file by simply using file pointer. I figurd out gotoxy 2 b a way of doin it ..but how do i move the fp and copy the specific text into a local var..
hi all
problem is.. i need 2 extract certain data fields from a text file by simply using file pointer. I figurd out gotoxy 2 b a way of doin it ..but how do i move the fp and copy the specific text into a local var..
So you want to jump to a certain point in a file? I think fseek() is what you're looking for ... http://www.cplusplus.com/reference/c...dio/fseek.html But that is a 1D file pointer setter. Doesn't work in X and Y. If every line in the file was the same length you could flatten an X and Y coordinate to a single offset.
ok thanks 4 fseek but dat wud move in one line (row)..as u said. how do i move 2 d next line...and how do i copy d text at d fie pointer location to a local var
OK. What you've gotta realise is that carrage returns, i.e. '\n' is also a character. Suppose I have the following file:with this code:01234
56789You'll notice the 6th position has the decimal value 10. In an ascii graph the 10th element is a new line. It doesn't care about the 2D-ness of the file. It just sees a series of stuff in a line. So if you wanted to move to get the 7, for example, from the file above you'd do something like:Code:int main () { int i; FILE * pFile; pFile = fopen ( "myfile.txt" , "r" ); for( i=0; i<10; i++ ) { printf( "Position %d has value %d\n", i+1, getc( pFile ) ); } fclose( pFile ); return 0; }fseek( pFile, 9 , SEEK_SET ); The 9 because it starts at 0 and counts the new line.Code:int main () { FILE * pFile; pFile = fopen ( "myfile.txt" , "r" ); fseek( pFile, 9 , SEEK_SET ); printf( "%c", getc( pFile ) ); fclose( pFile ); return 0; }