you declared name
as char
, that can hold only 1 character, generally any name is more than 1 character, so what you need is an array char name[50]
, and use %s
for reading it.
#include <stdio.h>
#include <stdlib.h>
int main()
{ char name[50] = {0};
int age;
printf("Enter your name:
");
scanf("%49s", name);
printf("Enter your age:
");
scanf("%d", &age);
printf("Your name is %s and your age is %d", name, age);
return 0;
}
&
prints the address of the variables, you just need to use only variable names in printf
Collect the return value of scanf
to check correct number of items are read
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…