利用带整数的scanf进行故障分割

利用带整数的scanf进行故障分割,c,gcc,C,Gcc,尝试使用以下函数从用户处读取整数输入时,我的C代码中出现分段错误: int userChoice = 0, tS; float tR, tW, tP, aP; char title[35], title2[35]; Book *curr; while (userChoice != 9) { printf("1. Determine and print total revenue\n"); printf("2. Determine and print total wholesale

尝试使用以下函数从用户处读取整数输入时,我的C代码中出现分段错误:

int userChoice = 0, tS;
float tR, tW, tP, aP;
char title[35], title2[35];
Book *curr;
while (userChoice != 9) {
    printf("1. Determine and print total revenue\n");
    printf("2. Determine and print total wholesale cost\n");
    printf("3. Determine and print total profit\n");
    printf("4. Determine and print total number of sales\n");
    printf("5. Determine and print average profit per sale\n");
    printf("6. Print book list\n");
    printf("7. Add book\n");
    printf("8. Delete book\n");
    printf("9. Exit the program\n");
    scanf("%d", userChoice);
    ...
    ...
每次我执行我的程序时,它允许我输入要分配给userChoice的编号,但seg会在之后立即出现故障。有什么帮助吗?谢谢

编辑:我得到的确切错误是:

Program received signal SIGSEFV, Segmentaion fault. 
0x0000003503256f50 in _IO_vfscanf_internal () from /lib64/libc.so.6
应该是:

scanf("%d", &userChoice);
需要用符号将其读入userChoice的位置,而不是userChoice的值

scanf("%d", userChoice);
=>


考虑一下:你是需要8个案例来引起碰撞,还是仅仅一个案例就可以?如果一个可以,为什么要给我们看八个?是否需要一个case语句,或者直线代码可以做到这一点?今后通读你的问题可能会有所启发。它不仅是一个很好的提问协议,也是一种很好的调试方法,可以帮助您在没有外界帮助的情况下解决自己的问题this@brostone51您正在使用的编译器没有很好地启用它,或者您正在使用一个古老的编译器。建议修复这样的问题,因为许多程序员都会错过这样的事情,但编译器会抓住它。节省你的时间。
scanf("%d", &userChoice);