这是我的代码:
int main(void) {
int userInt;
double userDouble;
char userChar;
char userString[50];
// FIXME: Define char and string variables similarly
printf("Enter integer:\n");
scanf("%d", &userInt);
printf("Enter double:\n");
scanf("%lf", &userDouble);
printf("Enter character:\n");
scanf("%c", &userChar);
printf("Enter string:\n");
scanf("%s", &userString);
printf("%d %f %c %s",userInt,userDouble,userChar,userString);
return 0;
}
这是输出所需要的:
Enter integer:
Enter double:
Enter character:
Enter string:
99 3.770000 z Howdy
这是当前输出的内容:
Enter integer:
Enter double:
Enter character:
Enter string:
99 3.770000
z
我假设以某种方式将空格或换行符分配给char,因此将z分配给字符串,但不确定如何避免这种情况。