与char*冲突的类型

1 c pointers function

我有一个小程序来测试传入和传出函数的char*指针.当我用cc编译时,我得到警告和错误,说我有相互冲突的类型,即使我的所有变量都是char*.请指教

#include <stdio.h>

main()
{
    char* p = NULL;

    foo1(p);
    foo2();
}

void foo1(char* p1)
{
}

char* foo2(void)
{
    char* p2 = NULL;

    return p2;
}

p.c:11: warning: conflicting types for ‘foo1’
p.c:7: warning: previous implicit declaration of ‘foo1’ was here
p.c:15: error: conflicting types for ‘foo2’
p.c:8: error: previous implicit declaration of ‘foo2’ was here
Run Code Online (Sandbox Code Playgroud)

Gav*_*n H 17

您需要在main()函数之前对函数进行原型设计.

例:

void foo1(char *p1);
char* foo2(void);

int main(.......
Run Code Online (Sandbox Code Playgroud)

或者只是将这些函数的主体放在主函数之上.