Getting Process returned -1073741819 (0xC0000005) error instead answer

-2

When I'm trying to get an answer, I'm getting this error: Process returned "-1073741819 (0xC0000005)". My goal is simple: I'm getting 4 numbers from the user, 1 number for menu and the other 3 are for doing math operation, but I can't get the answer: its stucking.

My code:

#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 : output

c
asked on Stack Overflow Oct 30, 2018 by Tasartir • edited Oct 30, 2018 by John Murray

1 Answer

1
scanf("%lf",r1);

The %lf format specifier to scanf expect a double *, but you're passing in a double. A mismatch between a format specifier and the given argument invokes undefined behavior, which in this case causes a crash.

Change it to:

scanf("%lf",&r1);
answered on Stack Overflow Oct 30, 2018 by dbush

User contributions licensed under CC BY-SA 3.0