Click to See Complete Forum and Search --> : Reading text file.


saroj
April 30th, 1999, 11:33 PM
Hi,

I tried to read the following data using fscanf (probably, it's not the best
but easy way) from a text file.

1 20 12 112 1222 3939 3939
2 20 12 112 1222 3939 3939
4 22 13 112 1222 3939 3939
4 22 13 112 1222 3939 3939 342333
4 22 13 112 1222 3939 3939 343333
4 22 13 112 1222 3939 3939 343332
4 22 13 112 1222 3939 3939 343332 232333

What I did is
fscanf(text_file,"%d %d %d %d %d %d %d %d
%d",c1,c2,c3,c4,c5,c6,c7,c8,c9,c10);

It won't worked
but
fscanf(text_file,"%d %d %d %d %d %d ",c1,c2,c3,c4,c5,c6,c7);

It worked for 1 to 3 lines.

I only want to request for a good suggestion that how could I read & insert
those contains into array or any via MFC.

pkraman
May 1st, 1999, 02:31 AM
hi,
you can use CStdioFile class for reading a line of text from a file. Create an object of CStdioFile and use ReadString() function to read a line from a file to a string( can be CString object). Then use strtok() function if the datas are seperated by spaces. you can get the elements in the array.

Regards,
Kalyan

zephyr79
March 17th, 2003, 04:04 AM
Hi, Pkraman

I'm using readstring command to read in data from textfile too.But for my case my data are separated by tab . But Readstring only allows me to read in the data before tab and ignore the rest.
Eg.

fmap famp1 famp2.

It can only managed to read in famp.

What shld i do? thanks