+ Reply to Thread
Results 1 to 2 of 2

Thread: sscanf does not work properly. Why?

  1. #1
    Senior Member
    Join Date
    Feb 2012
    Posts
    109

    sscanf does not work properly. Why?

    Code:
    void MyFunction()
    {
    	char szData[100] = "Name : <Roger>" ;
    
    	char szName[100] = "" ;
    	int nTimesScanned = sscanf(szData, "Name : <%s>", szName) ;
    }
    After function call "szName" is having "Roger>" string.

    I want to this string to be "Roger" only.

    How to resolve this issue?

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    37
    One possible solution could be:

    Code:
    void MyFunction()
    {
    	char szData[100] = "Name : <Roger>" ;
    
    	char szName[100] = "" ;
    	int nTimesScanned = sscanf(szData, "Name : <%[^>]", szName) ;
    }
    Does it make any sense?

+ 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