我是 C 初学者,目前正在学习如何在 C 中编写函数,下面是我的代码,我希望用户随机输入姓名和职业,然后用户随机输入将被替换为句子。问题是,当我运行这个特定的程序时,根本没有输出,我正在使用 CodeBlocks 及其控制台应用程序,但是当我构建、编译和运行它时,屏幕上没有任何内容,如下所示因此,“构建日志”部分中根本没有错误消息,您通常可以在其中看到错误,程序运行但不输出任何内容。
当程序运行时,我在控制台上看到的只是
“进程返回 0 (0x0) 执行时间:0.016 秒 按 ENTER 继续。”
#include <stdio.h>
#include <stdlib.h>
char FunOne(char Wun[50], char Two[50]);
int main()
{
char FunOne(char Wun[50], char Two[50]);
return 0;
}
char FunOne(char Wun[50], char Two[50])
{
printf("please enter a name: ");
fgets(Wun, 50, stdin);
printf("please enter a occupation: ");
fgets(Two, 50, stdin);
printf("there was once a man named %s", Wun);
printf("he lived in the UK and worked as a %s", Two);
return 0;
}
最佳答案
问题出在你的 main()
函数中,你应该这样做:
char FunOne(char Wun[50], char Two[50]); //declaration
int main()
{
char Wun[50], Two[50]; //declaration of variables (char arrays in this case)
FunOne(Wun, Two); //usage
return 0;
}
char FunOne(char Wun[50], char Two[50]) //definition
{
//...
}
关于C中的字符函数不输出任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60908760/