Parse a file

This is a discussion on Parse a file within the Windows Programming forums, part of the Platform Specific Boards category; I have a file called "db.ini" which contains a list of ilenames that all end with '0'. I want to ...

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

    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:

    Code:
    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;
                         FileNames.push_back(FileName);
             }
             else
             {
                         FileName = text;
             }
      }
      
    }
    
    ......
    hFile1 = CreateFile("db.ini", GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
    size = GetFileSize(hFile1, NULL);
    ReadFile(hFile1, &buffer, size, &dwNumRead, NULL);
    Parse();
    [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 05:06 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02:04 PM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 06:59 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM
  4. Hmm....help 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

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