-1

当我尝试编译我的简单启动程序时,我收到以下错误:

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  

我的代码文件是: main.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());
}

主文件

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

包括.h

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

进程命令.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();
}

进程命令.h

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

我相信这些都是我的源文件。我编译了

gcc main.c processcommand.c

谢谢您阅读此篇。

4

3 回答 3

2

processcommand.c中,它说

getinput()

什么是缩写

int getinput()

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

但是,在processcommand.h中,您有

char *getinput()

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

你可能想要在这两个地方是

char *getinput(void)

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

printoutputgetcommand 有同样的问题。

于 2013-05-31T15:30:58.833 回答
0

默认返回类型是int, 所以getinput()意味着int getinput()

尝试改变:

#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();
}

#include "processcommand.h"
char *getinput() {
char *output;
printf(" ");
scanf("%s", output);
return output;
}
unsigned char printoutput(char *input) {
printf("%s", input);
return 0;
}
char *getcommand() {
printoutput("Command:");
return getinput();
}
于 2013-05-31T15:31:46.537 回答
0

以下错误开头:

错误:...的类型冲突

是因为您没有按照声明的方式实现函数,例如您声明:

char *getinput();

但像这样实现:

getinput() {
char *output;
printf(" ");
scanf("%s", output);
return output;
}

它将假定返回值为int. 如果您像这样修改您的实现:

char *getinput() {
...

它应该修复该错误。与该错误无关,您需要为outputin分配内存getinput

char *output = malloc(...); // 

否则你正在写入一个未初始化的指针。

于 2013-05-31T15:31:05.937 回答