当用户尝试第二次输入数据(跳过第一次输入)时,我遇到fgets问题。第一次正常工作..如下图所示: enter image description here
我正在使用以下代码:
printf("Please Enter Following Information: \n\n\n");
printf("County (For Example - Hamilton,Ohio): \n");
fgets(strCounty, 49, stdin);
/* we should trim newline if there is one */
if (strCounty[strlen(strCounty) - 1] == '\n') {
strCounty[strlen(strCounty) - 1] = '\0';
}
printf("Race of head of Household (For Example - Asian): \n");
fgets(strRace, 49, stdin);
/* again: we should trim newline if there is one */
if (strRace[strlen(strRace) - 1] == '\n') {
strRace[strlen(strRace) - 1] = '\0';
}
printf("Number in Household: \n");
scanf("%d",&intHouseholds);
printf("The household yearly income: \n");
scanf("%d",&dblIncome);
我看过很多相关问题,但没有找到正确的答案 - 请帮助。