我正在编写代码以将输入保存在两个数组a和b中。
#include <stdio.h>
int tell(int *a, int *b)
{
/* I don't know what this function does */
return 0;
}
int main(int argc, char **argv)
{
int i, j, a[128], b[128];
i = 0;
while ((a[i] = getchar()) != 10) { // 10 represents enter key
i++;
}
printf("here");
j = 0;
while ((b[j] = getchar()) != 10) {
j++;
printf("here2\n");
}
printf("here3");
fflush(stdout);
if (i < j) {
printf("here4");
printf("%d\n", tell(a, b));
} else {
printf("here4");
printf("%d\n", tell(b, a));
}
return 0;
}
当我输入时:
hello
hi
输出为:
here
here2
here2
为什么不打印“ here3”?问题不只是在这里打印3。我想执行更多代码,但没有发生
该printf
函数将在看到时刷新输出缓冲区\n
。尝试:
printf("here3\n");
您还可以使用:
printf("here3");
fflush(stdout);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句