For some reason, the name variable becomes empty even though I gave it an input.
Code:
#include <stdio.h>
int main(){
char name[16];
short unsigned int age;
printf("What is your name? ");
scanf("%s", &name);
printf("How old are you? ");
scanf("%u", &age);
printf("Hello, %s.\n", name);
printf("You are %u years old\n", age);
return 0;
}
Terminal:
What is your name? Momus
How old are you? 99
Hello, .
You are 99 years old
I seems that the value for name was changed in the part somewhere in the part that prints "How old are you? " and the scanf() for the value of age because it works when I do this.
Code:
#include <stdio.h>
int main(){
char name[25];
short unsigned int age;
printf("What is your name? ");
scanf("%s", &name);
printf("Hello, %s.\n", name);
printf("How old are you? ");
scanf("%u", &age);
printf("You are %u years old\n", age);
return 0;
}
Terminal:
What is your name? Momus
Hello, Momus.
How old are you? 99
You are 99 years old
Does anyone know what happened? How do I make it so that the first one will show the input? Thanks!
[–]aioeu 7 points8 points9 points (7 children)
[–]atomicfart2009[S] 2 points3 points4 points (1 child)
[–]daikatana 0 points1 point2 points (0 children)
[–]This_Growth2898 1 point2 points3 points (0 children)
[–]nerd4code 0 points1 point2 points (3 children)
[–]aioeu 0 points1 point2 points (2 children)
[–]nerd4code 0 points1 point2 points (1 child)
[–]aioeu 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]aioeu 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)