sscanf() for just one field
-
How to read from a string char str[] = "field1 field2 field3 ..." only one field3 string using sscanf() and one buffer for it - tmp. sscanf(str,"%s %s %s",0,0,tmp); it produces exception in this case
9ine
Or like this. N.B. Add error handling as required!
char str[] = "field1 field2 field3 ..." // only one field3 string using sscanf() and one buffer for it - tmp. char * cpLastSpace = strrchr(str, (int) ' '); // Find the last space in str if(NULL != cpLastSpace) { sscanf(cpLastSpace+1,"%s",tmp); // Or strcpy(tmp, cpLastSpace+1); }
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
-
I did not know sscanf could do that. Wow. I am gonna remove all stringstreams from my code, right now ;)
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
Sebastian Schneider wrote:
I am gonna remove all stringstreams from my code, right now
are you serious :~ C++ classes are much prefered than C functions dude!
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
9ine wrote:
sscanf(str,"%s %s %s",0,0,tmp);
Use:
sscanf(str, "%*s %*s %s", tmp);
9ine wrote:
it produces exception in this case
As it should since you are trying to write to address 0.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
-
I did not know sscanf could do that. Wow. I am gonna remove all stringstreams from my code, right now ;)
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
Sebastian Schneider wrote:
Wow. I am gonna remove all stringstreams from my code, right now
I do hope you were being sarcastic :-P sscanf is great when parsing typed information ... it is not very useful for trying to extract substrings.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
I did not know sscanf could do that. Wow. I am gonna remove all stringstreams from my code, right now ;)
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
Sebastian Schneider wrote:
I am gonna remove all stringstreams from my code, right now
are you serious :~ C++ classes are much prefered than C functions dude!
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
toxcct wrote:
are you serious
Hrhr.
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
Sebastian Schneider wrote:
Wow. I am gonna remove all stringstreams from my code, right now
I do hope you were being sarcastic :-P sscanf is great when parsing typed information ... it is not very useful for trying to extract substrings.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
I was. Oh, and I noticed 2 typos in your Signature:
Zac Howland wrote:
...for 8 hours a day, 5 days a week
should be
experience tells us:
...for 11 hours a day, 6 days a week
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
I was. Oh, and I noticed 2 typos in your Signature:
Zac Howland wrote:
...for 8 hours a day, 5 days a week
should be
experience tells us:
...for 11 hours a day, 6 days a week
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
Just checking ... And I've thought about changing it to say "at least 8 hours ... 5 days" since my old job fit the 20 hour/7 day mold.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Just checking ... And I've thought about changing it to say "at least 8 hours ... 5 days" since my old job fit the 20 hour/7 day mold.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
Gotta loooooove crunch-time...
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
-
Gotta loooooove crunch-time...
Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.
Oh no. That was normal operating procedure ... When crunch time came around, the managers would pressure us to spend the night in the office ... even over weekends!
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac