segmentation fault using scanf with integer

后端 未结 2 1612
猫巷女王i
猫巷女王i 2020-11-27 23:53

I am getting a segmentation fault in my C code when trying to read integer input from the user with the following functon:

int userChoice = 0, tS;
float tR,         


        
相关标签:
2条回答
  • 2020-11-28 00:00
    scanf("%d", userChoice);
    

    =〉

    scanf("%d", &userChoice);
    
    0 讨论(0)
  • 2020-11-28 00:16

    Should be:

    scanf("%d", &userChoice);
    

    Need the ampersand to read it into the location of userChoice, and not the value of userChoice.

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