简体   繁体   中英

C program stops in the middle of running

Hi im new here also im new to programming and id like you to help me on this : to problem is that after compiling and running the program it stops in the middle of it when running and i didnt know what is causing this and sorry for the unreadable previous post : here is my program :

char answer[15];
char place[15];
char fullname[15];
int age;
printf("What Is Your Full Name?: ");
scanf("%s",fullname);
printf("What Is Your Age?: ");
scanf("%d",age);
printf("Where Do You Live?: ");
scanf("%s",place);

if(strcmp(place,"gafsa")==0) {
    printf("Aint a bad place you know");
}
else{
    printf("hmmm %s cool\n",place);
}

printf("your name is %s, %d year old from %s is that right?: ",fullname,age,place);
scanf("%s",answer);

if(strcmp(answer,"yes")==0){
    printf("you my friend are awesome\n");
}
else{ 
    printf("you suck\n");
}

and this is an image to show the problem clearly:

http://i.stack.imgur.com/yFTwK.png

You need to pass the address of the variable:

scanf("%d",&age);
           ^

You're taking input at a memory location of value of uninitialized age . ie some garbage

Use:

scanf("%d",&age); // notice & , pass address of variable age

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM