Need help for CFile read

This is a discussion on Need help for CFile read within the C++ Programming forums, part of the General Programming Boards category; Hi all, Can someone help me out with this? I would like to read from a file which contain alot ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    1

    Need help for CFile read

    Hi all, Can someone help me out with this? I would like to read from a file which contain alot of numbers and few letters.
    I try out the code below.

    CFile f1;
    f1.Open("C:/abc/t1", CFile::modeRead| CFile::shareExclusive);
    int len = f1.GetLength();
    char* buf = new char[len+1];
    f1.Read(buf, len);
    while(scanf(buf, "%lf %lf %lf\n", %a, %b, %c);
    {
    //read out the number and letter then do some compare and printf to a new FILE* f2
    }
    f1.Close();


    Using that code, my output result is diff from FILE* f1, fopen, and fscanf.
    I am thinking whether is the problem due to scanf from char* cos if using FILE*, fscanf(f1, "%lf %lf %lf\n", %a, %b, %c); will be ok. That is scanf from file. For my CFile one, it is scanf from char*. So ??????
    I need to use CFile cos i don't want other to open my file when my program is using it. Want to set some security. Please help me out. Thanks alot.
    Attached Files Attached Files
    Last edited by nicholasamh; 10-22-2009 at 08:10 AM.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    That scanf call looks suspicious. Shouldn't that be sscanf and shouldn't there be more parameters, for example the variables you want to read into?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read() problems
    By yay4rei in forum C Programming
    Replies: 2
    Last Post: 07-21-2005, 11:47 AM
  2. How can I know the actual bytes read in a file read
    By pliang in forum C++ Programming
    Replies: 1
    Last Post: 06-08-2005, 05:23 PM
  3. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 04:32 PM
  4. Read Array pro!!Plz help!!
    By Supra in forum C Programming
    Replies: 2
    Last Post: 03-04-2002, 03:49 PM
  5. Help! Can't read decimal number
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 09-07-2001, 03:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21