scanf的分段错误

时间:2013-12-05 12:34:26

标签: c error-handling

这是rsa加密的代码

#include <stdio.h>
#include <math.h>

main()
{
    int N;

    int e;

    int number1;

    int number2;

    int number3;

    int number4;

    printf("This is an RSA Cryptosystem program to help encrypt four letter Vigenere     keywords.\n");

    printf("Enter your N\n");

    scanf("  %d", N);

    printf("Enter your e\n");

    scanf("  %d", e);

    printf("Enter the first number that corresponds to the first letter of your key.\n");

    scanf("  %d", number1);

    printf("Enter second\n");

    scanf("  %d", number2);

    printf("Enter third'n");

    scanf("  %d", number3);

    printf("Enter final number\n");

    scanf("  %d", number4);



    int crypt1 = pow(number1, e);

    int crypt2 = pow(number2, e);

    int crypt3 = pow(number3, e);

    int crypt4 = pow(number4, e);



    int crypt5 = crypt1 % N;

    int crypt6 = crypt2 % N;

    int crypt7 = crypt3 % N;

    int crypt8 = crypt4 % N;



    printf("Your encrypted keyword is: %d,%d,%d,%d.\n", crypt5, crypt6, crypt7, crypt8);

    return 0;
}

我遇到了分段错误(核心转储)。

1 个答案:

答案 0 :(得分:4)

你在&的论点中错过了scanf

更改

scanf("  %d", N);  

scanf("  %d", &N);  

同样适用于所有scanf的论点。