2013-01-20 75 views
0

這是我朝的main()的結束代碼:用C奇怪的堆棧錯誤錯誤在Visual Studio

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

爲什麼?我該如何解決它?

+0

什麼'exitOption'的定義是什麼? –

+0

你也應該知道[遞歸到main()](http://stackoverflow.com/questions/4518598/is-it-legal-to-recurse-into-main-in-c)是未定義的行爲。 – WhozCraig

回答

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