获取流程返回-1073741819(0xC0000005)错误,而不是回答

时间:2018-10-30 18:32:30

标签: c

当我试图获得答案时,出现此错误:     进程返回“ -1073741819(0xC0000005)”。 我的目标很简单:我从用户那里得到4个数字,其中1个用于菜单,另外3个用于进行数学运算,但是我找不到答案:它卡住了。

我的代码:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int menu,t1,t2,sonuc1;
    double r1,sonuc,sonuc2;
    printf("\t*************Menu*****************\n");
    printf("\n");
    printf("1.\t SADECE TAM SAYILARI TOPLA\n");
    printf("2.\t TAM SAYILARI TOPLA REEL SAYI ILE CARP\n");
    printf("3.\t REEL SAYININ KARESİNİ ALARAK 1.TAM SAYI İLE ÇARP\n");
    printf("4.\t CIKIS\n");
    printf("Seciniz:");
    scanf("%d",&menu);
    if(menu == 4){
        printf("Hoscakal");
        return 0;
    }
    else if (menu !=1 && menu !=2 && menu !=3){
        printf("Gecersiz Deger!");
        return 0;
    }
    printf("\nBirinci tam sayiyi giriniz: ");
    scanf("%d",&t1);
    printf("\nIkinci tam sayiyi giriniz: ");
    scanf("%d",&t2);
    if (t2==0){
            t2 = 1;
        }
    printf("\nReel sayiyi giriniz: ");
    scanf("%lf",r1);
    if(r1>0 || r1 == 0){
        r1 = -1;
    }
    if(menu == 1){
            sonuc1 = (t1+t2);
    printf("Sonuc: %d",sonuc1);
    }
    else if(menu == 2) {
            sonuc = (t1+t2)*r1;
        printf("Sonuc: %lf",sonuc);
    }
    else if(menu == 3) {
            sonuc2 = (r1*r1)*t1;
        printf("Sonuc: %lf",sonuc2);
    }
}

输出:output

1 个答案:

答案 0 :(得分:1)

scanf("%lf",r1);

%lf的{​​{1}}格式说明符期望scanf,但是您传入的是double *。格式说明符和给定参数之间的不匹配会调用undefined behavior,在这种情况下会导致崩溃。

将其更改为:

double