The following is my problem. When I try to use the following code to output, why does the output result, the value of the variable age
becomes 0
. (Note: I am using the GCC compiler to try in VScode, and I will not have this problem when I try it in vstudio2019)
#include <stdio.h>
int main(){
int age;
char x;
printf("Please enter age:");
scanf("%d", &age);
printf("Please enter gender: ");
scanf("%s", &x);
printf("%d,%s",age,x);
return 0;
}
Thanks for the answer, I understand that %s needs to be intercepted to a null character, but I made the following changes, just let it output the value of age
, and still output the result as 0
, I don't quite understand, these two variables Will they affect each other?
#include <stdio.h>
int main(){
int age;
char x;
printf("Please enter age:");
scanf("%d", &age);
printf("Please enter gender: ");
scanf("%s", &x);
printf("%d",age);
return 0;
}