Thread: Need help for CFile read

  1. #1
    Registered User
    Join Date
    Oct 2009

    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

    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.
    Last edited by nicholasamh; 10-22-2009 at 07:10 AM.

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    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?

    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, 10: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, 04:23 PM
  3. What Would You Use To Read User Input?
    By djwicks in forum C Programming
    Replies: 11
    Last Post: 04-05-2005, 03: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, 02:09 AM