gpt4 book ai didi

涉及函数声明两次且类型不同的编译错误

转载 作者:行者123 更新时间:2023-11-30 18:58:23 25 4
gpt4 key购买 nike

当我尝试编译简单的入门程序时,出现以下错误:

In file included from processcommand.c:1:
processcommand.h:5: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
processcommand.c:3: error: conflicting types for 'getinput'
processcommand.h:3: error: previous declaration of 'getinput' was here
processcommand.c: In function 'getinput':
processcommand.c:8: warning: return makes integer from pointer without a cast
processcommand.c: At top level:
processcommand.c:12: error: conflicting types for 'printoutput'
processcommand.h:4: error: previous declaration of 'printoutput' was here

我的代码文件是:ma​​in.c

#include "main.h"

int main() {
float version = 0.2;
printf("Qwesomeness Command Interprepter version %f by Zeb McCorkle starting...\n", version);
printf("%s", getcommand());
}

ma​​in.h

#include "includes.h"
int main();

includes.h

#include <stdio.h>
#include <string.h>

processcommand.c

#include "processcommand.h"
getinput() {
char *output;
printf(" ");
scanf("%s", output);
return output;
}

printoutput(char *input) {
printf("%s", input);
return 0;
}

getcommand() {
printoutput("Command:");
return getinput();
}

processcommand.h

#include "includes.h"
char *getinput();
unsigned char printoutput(char *input);
char *getcommand();

我相信这些就是我的所有源文件。我编译的是

gcc main.c processcommand.c

感谢您阅读本文。

最佳答案

processcommand.c中,它说

getinput()

什么是缩写

int getinput()

这是一个具有未指定参数和 int 返回值的函数。

但是,在processcommand.h中,您有

char *getinput()

这是一个具有未指定参数和 char * 返回值的函数。

您在这两个地方可能想要的是

char *getinput(void)

这是一个没有参数和 char * 返回值的函数。

printoutputgetcommand 也有同样的问题。

关于涉及函数声明两次且类型不同的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16860778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com