For a project I'm trying to read an int and a string from a string. Here the only problem is sscanf appears to break reading an %s
when it sees a space and some special character. I want to print only String which is present inside special character. Is there anyway to get around this limitation? Here is an example of what I'm trying to do:
Similar to this link with little change
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char** argv) {
int age;
char* buffer;
buffer = malloc(200 * sizeof(char));
sscanf("19 cool kid >>> ram <<<", "%d %[^\t\n] >>> %*s <<<", &age, buffer);
printf("%s is %d years old\n", buffer, age);
return 0;
}
What it prints is: "cool kid >>> ram <<< is 19 years old" where I need "ram is 19 years old". Is there any work around?
Note: some time "cool kid" string come "coolkid" like this also.