Visual Studio中C中奇怪的堆栈错误错误

时间:2013-01-20 04:07:59

标签: c stack main

这是我在main()结束时的代码:

printf("Would you like to find data on another 20 rods? \nType C and press enter to continue, or type E and press enter to exit \n");

scanf("%s",&exitOption);

if (exitOption == 'C'){
main();

}

return 0;   

每次运行程序时都会收到此错误:

enter image description here

为什么呢?我该如何解决?

1 个答案:

答案 0 :(得分:3)

exitOption必须是一个字符

scanf("%c",&exitOption);

即使您正在尝试获取字符串,也必须采用这种方式

char string[10];
printf("Enter string\n");
scanf("%s",string);  // note the second parameter of scanf() when u get a string