Thread: Parse a file

  1. #1
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006

    Parse a file

    I have a file called "db.ini" which contains a list of ilenames that all end with '0'. I want to parse this data and find and remove the '0' and then store the new filenames in a vector of strings. This is the code i have so far but i am having a bit of trouble with making it loop onto the next file. Any ideas would be greatly appreciated:

    LPCVOID buffer[9999];
    char TempBuffer[sizeof(buffer)] = "";
    HANDLE hFile1;
    DWORD size;
    LPCSTR FileName;
    vector<LPCSTR> FileNames;
    LPCSTR Parse()
      char text[sizeof(buffer)] = "";
      memcpy(TempBuffer, &buffer, sizeof(buffer));    
      for (x = 0; x != sizeof(TempBuffer); x++)
             text[x] = TempBuffer[x];
             if (text[x] == '0')
                         text[x] = text[x + '0'];
                         FileName = text;
                         FileName = text;
    hFile1 = CreateFile("db.ini", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    size = GetFileSize(hFile1, NULL);
    ReadFile(hFile1, &buffer, size, &dwNumRead, NULL);
    [EDIT] Forgot to mention it gets the first name of the filenames in "db.ini" ok[/EDIT]
    Last edited by L_U_K_E; 04-03-2007 at 04:06 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > LPCVOID buffer[9999];
    What's this got to do with anything?

    In short, why aren't you using the standard C++ streams to read a line at a time into a std::string, rather than trying to pre-optimise everything by reading the whole file into a big dumb buffer which might not be big enough to begin with.

    > text[x] = text[x + '0'];
    Replace a character with a character which is 48 places away ???
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM