input from fgets not stored using sscanf properly

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 main(void) { int i, x, y; char input[28]; char* name = NULL; fgets(input, 28, stdin); sscanf(input, "%s %i %i", name, &x, &y); printf("%s %i %i\n", name, x, y); return 0; } 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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准