So I have this small part of my code (basically the input for my whole program).
It has to take the form of a string with at most 20 characters, and two integers all separated by a space.
eg master 1 1
int i, x, y;
char* name = NULL;
fgets(input, 28, stdin);
sscanf(input, "%s %i %i", name, &x, &y);
printf("%s %i %i\n", name, x, y);
Basically I'm trying to print it out to see if the program is storing the input correctly, as it has to be stored in a linked list later on.
Everything worked fine, but no matter what I type, It prints out (null) 0 4196064. It seg faults if I put and ampersand infront of name in the sscanf() function as well.
Any ideas on how to fix this would be much appreciated!
以上就是input from fgets not stored using sscanf properly的详细内容，更多请关注web前端其它相关文章！