+ Reply to Thread
Results 1 to 2 of 2

Thread: Need help with sscanf in C++

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    28

    Need help with sscanf in C++

    I have following example code:

    Code:
    void ParseString()
    {
    	char *pInput = "SURNAME FIRSTNAME LASTNAME 12 NEWYORK" ;
    
    	char szSurname[100] = "" ;
    	char szFirstName[100] = "" ;
    	char szLastName[100] = "" ;
    	int nAge ;
    
    	int result = sscanf(pInput, "%s %s %s %d", szSurname, szFirstName, szLastName, &nAge) ;
    }
    Issue is that I do not want to get szSurname from the input string. But here I have to crate and specify the variable.

    Can I do this and get directly szFirstName from the input string and skip the szSurname?

    Any help would be much appreciated!

    Thanks.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    24
    You can use "%*s" for this.

    Below is the example:

    Code:
    void ParseString()
    {
    	char *pInput = "SURNAME FIRSTNAME LASTNAME 12 NEWYORK" ;
    
    	char szSurname[100] = "" ;
    	char szFirstName[100] = "" ;
    	char szLastName[100] = "" ;
    	int nAge ;
    
    	int result = sscanf(pInput, "%*s %s %s %d", szFirstName, szLastName, &nAge) ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts