The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sscanf function is failing jxh461 High Level Programming 0 02-13-2007 08:10 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-06-2007
Registered User
 

Join Date: Apr 2007
Posts: 75
sscanf !!

I have a string

Quote:
\\\\?\\whats going on
Form this string, I want to extract

Quote:
whats going on
I am unable to do that with sscanf because of the space between the words. What else can I use?

Code:
#include <stdio.h>

char buf_2[50];

int
main()
{
        char *buf_1 = "\\\\?\\whats going on";

        sscanf(buf_1, "\\\\?\\%s", buf_2);

        printf("buf_1 = %s\n", buf_1);
        printf("buf_2 = %s\n", buf_2);

        printf("Thats all folks... !\n");

        return 0;

}
The output of the above program is:

Quote:
buf_1 = \\?\whats going on
buf_2 = whats
Thats all folks... !
thanks
Reply With Quote
Forum Sponsor
  #2  
Old 12-06-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
Code:
char *buf_2=buf_1;

if (!memcmp(buf_2,"\\\\?\\",4)) buf_2+=4;
Reply With Quote
  #3  
Old 12-06-2007
Registered User
 

Join Date: Apr 2007
Posts: 75
Proter ! thats just awesome man... Thanks !!
Reply With Quote
  #4  
Old 12-06-2007
Registered User
 

Join Date: Jan 2007
Posts: 2,965
As long as you understand what it is doing.
Reply With Quote
  #5  
Old 12-10-2007
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
Change your sscanf as below and then try.

sscanf(buf_1, "\\\\?\\%49c", buf_2);
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:49 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0