【发布时间】:2014-05-24 21:26:24
【问题描述】:
所以我制作了这个程序来扫描地址,然后询问用户是否要插入另一个地址或打印已经插入的地址。当我运行它时,我会检查一次,然后我为 &y 插入的内容会打印一个随机数,然后再次打印带有注释的行并扫描 &y。我觉得它第二次通过 do-while 循环跳过了 fgets 函数。救命!
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main (void)
{
char address[10][100];
int x;
char y;
for(x=0;x<10;x++){
do {
printf("Enter address %d:", x + 1); //prints this second time through
fgets(address[x], 100, stdin); //doesnt scan for this second time through
printf("Do you want to print address's inserted thus far or continue?(p or c):"); // prints this second time through also.
scanf("%d" , &y);
if (y == "c") continue;
else
printf("%d" , &y);
break;
} while (strcmp(address[x], "\n") == 0);
}
return(0);
}
【问题讨论】:
-
注意编译器给你的错误信息。
标签: c loops while-loop scanf fgets