![]() |
|
#1
|
|||
|
|||
eating single space in scanfSince a space in scanf()'s format matches all white-space, I was wondering if there is a way to make scanf() eat a single space in the middle of a format? (Yes, yes, I will be using sscanf, not scanf itself =)
|
|
#2
|
|||
|
|||
|
Quote:
Give an example of the input line (string) and what you want to do with it. Regards, Dave |
|
#3
|
|||
|
|||
|
It's basically for a simple HTTP daemon, for parsing requests. Example of a good request would be "GET /foo HTTP/1.0" where all white-space are single spaces, but "GET /foo HTTP/1.0" is an invalid request because of the multiple spaces. I guess I could just walk through the buffer char by char (the request string is already in a buffer) but using sscanf() seemed like a better idea, or at least would be if it's able to detect single spaces.
|
|
#4
|
||||
|
||||
|
Quote:
Another idea is to use sscanf()'s "read until whitespace" functionality and set up a loop until you're out of string. But after each read you must remove what was read from the original buffer which can be a fair amount of work. A third way (and better in my opinion), is to move the string char by char into another buffer, ignoring multiple whitespace. It's easiest, faster, and you're sure to get it right. See the tutorial Things to avoid in C/C++ for a discussion on scanf(), which also goes for sscanf() for the most part. __________________
Age is unimportant -- except in cheese |
|
#5
|
|||
|
|||
|
Char-by-char it is then =) Things like this make me long for perl. Thanks for your reply!
|
|
#6
|
||||
|
||||
|
Quote:
If you design this task as a function, keep it handy. You now have your "perl-like" function. After all, that's probably all perl does. As you develop more functions that seem useful, keep them in a special library directory so you can find and use them again. __________________
Age is unimportant -- except in cheese |
Recent GIDBlog
Halfway done! by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| single doc interface in MFC | vadharah | MS Visual C++ / MFC Forum | 0 | 26-May-2004 04:10 |
| Art and Maths.....a single hypervoxel | paulselhi | Graphics Forum | 0 | 10-Mar-2004 06:11 |
| 600MB Space, 20GB Banwidth, PHP, MySQL, CGI, SSH, FrontPage, FTP, POP3, Web Mail | fcolor | Web Hosting Advertisements & Offers | 0 | 08-Aug-2003 10:11 |
| Hosting under $8/month: 10-20GB Transfer, 300-600MB Space, PHP, MySQL, Domain Name! | fcolor | Web Hosting Advertisements & Offers | 0 | 28-Feb-2003 04:48 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The