Text file parsing

This is a discussion on Text file parsing within the C++ Programming forums, part of the General Programming Boards category; how in C++ would you go about parsing text files....

  1. #1
    Unregistered
    Guest

    Text file parsing

    how in C++ would you go about parsing text files.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    It depends on the format of the text file. What do you want to do? Read something like a .ini file (pairs of identifiers/values), make a scripting langauge? Read straight data?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    My guess is that in C you would use pointers or indexes into arrays, while in C++ you would use iterators and generic containers.

  4. #4
    Shadow12345
    Guest
    What is parsing?
    (no I don't know what parsing means, shoot me)

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    !bang!
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  6. #6
    Unregistered
    Guest

    I'm not sure,

    What I need to do is parse a text file for commands.



    example:


    MakeWin("Window Title Goes Here", left, top, 100,100)

    and I need these commands to run in my main program.

    I have these functions in my program I just need to get the commands from the file to implement them.

  7. #7
    Unregistered
    Guest

    in case this will help

    void MakeWin(char *WindowTitle, int x, int y, int xx, int yy);


    is how I declared the function and then I have a library that has that function within it, that I have written.

    I am making a multitasking gui app for dos that I uses my own custom commands for both drawing and getting mouse clicks, etc.

    The only way I have found to multitask is to execute scripts rather than .exe files.

  8. #8
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Code:
    [File.txt]
    Window Title ;self explanitory
    100 ;x
    100 ;y
    100 ;width
    100 ;height
    Code:
    [Part of File.cpp]
    char WindowTitle[100];
    char x[4], y[4], width[4], height[4];
    int ix, iy, iwidth, iheight;
    ifstream fileload("File.txt");
    
    fileload.getline(WindowTitle, 100, ';');
    fileload.getline(x, 4, ';');
    fileload.getline(y, 4, ';');
    fileload.getline(width, 4, ';');
    
    ix = atoi(x);
    iy = atoi(y);
    iwidth = atoi(width);
    iheight = atoi(height);
    
    MakeWin(WindowTitle, ix, iy, iwidth, iheight);
    I dont know if you can get ints with getline() so i just stored them in a char then atoi'd them
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  9. #9
    Unregistered
    Guest
    Thanks much okismokie, um

    is there a way to keep the command and the variables on the same line like the cpp compilers do.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Parsing specific data from one text file to another..
    By chops11 in forum C Programming
    Replies: 2
    Last Post: 09-13-2005, 10:50 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 02:58 PM

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