Scanf causes C program to crash

前端 未结 2 1178
半阙折子戏
半阙折子戏 2020-11-30 15:03

This simple issue is causing my entire program to crash during the first input. If I remove the input, the program works fine but once I add scanf into the code and enter th

相关标签:
2条回答
  • 2020-11-30 15:57

    You must pass the address of the variable to scanf:

     scanf("%c", &answer);
    
    0 讨论(0)
  • 2020-11-30 16:00

    Use "&answer". And get rid of the extraneous "fflush()" commands...

    Better, substitute "answer = getchar ()".

    0 讨论(0)
提交回复
热议问题