For a project I'm trying to read an int and a string from a string. The only problem is sscanf()
appears to break reading an %s
when it sees a space. Is there anyway to get around this limitation? Here's an example of what I'm trying to do:
#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", "%d %s", &age, buffer);
printf("%s is %d years old
", buffer, age);
return 0;
}
What it prints is: cool is 19 years old
where I need cool kid is 19 years old
. Does anyone know how to fix this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…