darksphere
darksphere

Reputation: 59

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:

https://i.sstatic.net/yFTwK.png

Upvotes: 0

Views: 2600

Answers (2)

UltraInstinct
UltraInstinct

Reputation: 44424

You need to pass the address of the variable:

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

Upvotes: 3

P0W
P0W

Reputation: 47784

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

Use:

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

Upvotes: 1

Related Questions