你能告诉这里有什么问题吗?
#include <stdio.h>
#include <stdlib.h>
int test (void)
{
int i;
printf("Enter a number: ");
scanf("%d",&i);
return i;
}
int main (void)
{
test();
return 0;
}
这只是一个简单的示例,但由于某种原因,除非我摆脱了 scanf,否则 main 不会运行。
始终'\n'在 printf 字符串的末尾使用 a 。这使得输出缓冲区刷新并打印字符串。在您的程序中添加更多打印。你可以像下面这样重写你的程序,打印将帮助你了解你的程序发生了什么。
#include <stdio.h>
#include <stdlib.h>
int test (void)
{
int i;
printf("Enter a number: \n");
scanf("%d",&i);
printf("You just eneterd : %d\n",i);
return i;
}
int main (void)
{
printf("About to call test() \n");
test();
printf("Done calling test() \n");
return 0;
}
最好买一本好的 C 编程书来理解这些基本的东西。我建议C 编程语言
我认为您必须使用 fflush() 或在 printf 函数末尾使用 '\n' 字符,这最终将刷新 std 输出缓冲区。为了检查,只需在读取值后使用 printf() 打印变量的值。
希望有帮助....