CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 1999
    Posts
    2

    Reading text file.

    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.






  2. #2
    Join Date
    Apr 1999
    Location
    Chennai, INDIA
    Posts
    27

    Re: Reading text file.

    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


  3. #3
    Join Date
    Feb 2003
    Posts
    35
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured