当我运行代码时,它确实要求我输入年龄。但是没有要求输入性别?这个代码有什么问题。
#include<stdio.h>
#include<conio.h>
int main(void)
{
int age;
char sex;
printf("Enter your age \n");
scanf("%d",&age);
printf("Your age is %d \n",age);
printf("Enter your sex \n");
scanf("%c",&sex);
printf("Your sex is %c \n",sex);
getch();
return 0;
}
scanf()
的返回值:if (scanf(...) != N) /* error */;
其中N
是预期分配的数量。 - pmg