Thread: Hi ... parsing a char*

  1. #1
    Registered User
    Join Date
    Aug 2010
    Posts
    8

    Hi ... parsing a char*

    Hi ... I'm new to c++ programming and i'm trying to parse a large char* which contains something like this :

    Header 1
    Header 2

    Login name

    a=1234123
    b=23423
    c=23432
    a=qwerty
    and i need to save them into variables (array of strings maybe? )

    Here is my try ... I dont know how to take all the chars and put then on the string ... also if you think of a better way of doing this it would be great !!! thank you

    Code:
    void parsing(char* reply){
    
        int j=0;
    
        for(int i=0;i<reply.length();i++){
    
            int next=i+1;
            int fwd=i+2;
    
    
            if( (reply[i]=='\n')&&(reply[fwd]=='=') ){
    
                parsedhead[j]=reply[next];
                parseddata[j]= //HELP HERE :(
                j++;
            }
    }
    }
    both arrays i have then already declared

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Use C++ strings if you're actually programming in C++ and use stringstream - C++ Reference

  3. #3
    Registered User
    Join Date
    Aug 2010
    Posts
    8
    Thank you. I took a look at what you mentioned but still haven't been able to make it work, because I dont know how to limit what I'm extracting .

    I could use getline() and store each line separately in a string array but I would still need to check if what I got is one of the parameters I need .. I dont want the headers to be stored. What I think that differences the data I want is a \n then a character which can be a, b, c d, e and then a '='.

    What I would need is a way to extract from a char* to a string some data until \n+char+= combination arrives ... what do you think ?

    Edit: I almost got it, combining some for, while and using substr But it doesn't sem to work ok, the string that I got is too long. That reference you posted is helping me a lot, thanks again !

    xxx
    Last edited by JessH; 08-16-2010 at 04:02 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need sth about parsing
    By Masterx in forum C++ Programming
    Replies: 6
    Last Post: 11-07-2008, 12:55 AM
  2. draw tree graph of yacc parsing
    By talz13 in forum C Programming
    Replies: 2
    Last Post: 07-23-2006, 01:33 AM
  3. Parsing for Dummies
    By MisterWonderful in forum C++ Programming
    Replies: 4
    Last Post: 03-08-2004, 05:31 PM
  4. Need help fixing bugs in data parsing program
    By daluu in forum C Programming
    Replies: 8
    Last Post: 03-27-2003, 06:02 PM
  5. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM