.h 声明函数

qq_41233302 2017-11-30 11:15:37
哭了
用.h声明了一个函数 为什么函数里会出现warning: implicit declaration of function 'printf' [-Wimplicit-function-declaration]|
warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]|
error: 'txl' undeclared (first use in this function)|
...全文
559 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_41233302 2017-12-04
  • 打赏
  • 举报
回复
引用 16 楼 lzb4207123 的回复:
[quote=引用 15 楼 qq_41233302 的回复:] [quote=引用 14 楼 lzb4207123 的回复:] 看了下 你的错误提示 你那里有用到 tianjia()这个函数吗 里面的报错是 在tianjia()中的
有的 tianjia是在zhucaodan里的[/quote] 把那部分代码贴出来一下 zhucaodan() 和 tianjia() 的[/quote]
void zhucaodan()
{
    char c;
    system("cls");
    printf("\n\t\t|-------欢迎您使用通讯录管理系统1.0beat版-----|");
    printf("\n\t\t|    1-添加联系人       2-查询和显示联系人");
    printf("\n\t\t|    3-删除联系人       4-修改联系人");
    printf("\n\t\t|    5-保存退出         6-不保存退出");
    printf("\n\t\t请选择您所所要的服务:");

    c = getch();

    switch(c){
    case '1':
        tianjia();
        break;

    case '2':
        chaxun();
        break;

    case '3':
        shanchu();
        break;

    case '4':
        xiugai();
        break;

    case '5':
        baocun();
        break;
    case '6':
        exit(0);

    default:
        zhucaodan();
    }
}
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

void tianjia()
{
printf("\n\t\t------------------ 请输入联系人信息 --------------------\n");
printf("\n\t\t输入联系人姓名:");
scanf("%s",txl[n].xingming); /*键盘输入*/
printf("\n\t\t输入联系人电话号码:");
scanf("%s",txl[n].dianhua);
printf("\n\t\t输入联系人地址:");
scanf("%s",txl[n].dizhi);
n++; /*统计个数*/
printf("\n\t\t是否继续添加联系人?(Y/N):"); /*是否继续输入联系人.*/
if (getch()=='y')
tianjia();
return;

}

qq_41233302 2017-12-04
  • 打赏
  • 举报
回复
引用 19 楼 lzb4207123 的回复:
在tianjiah函数.c文件中也加上 main.h的头文件 要不程序认不到你在main.h中定义的 “n”和“txl”
终于好了 谢谢大佬
lzb4207123 2017-12-04
  • 打赏
  • 举报
回复
在tianjiah函数.c文件中也加上 main.h的头文件 要不程序认不到你在main.h中定义的 “n”和“txl”
lzb4207123 2017-12-04
  • 打赏
  • 举报
回复
引用 17 楼 qq_41233302 的回复:
[quote=引用 16 楼 lzb4207123 的回复:] [quote=引用 15 楼 qq_41233302 的回复:] [quote=引用 14 楼 lzb4207123 的回复:] 看了下 你的错误提示 你那里有用到 tianjia()这个函数吗 里面的报错是 在tianjia()中的
有的 tianjia是在zhucaodan里的[/quote] 把那部分代码贴出来一下 zhucaodan() 和 tianjia() 的[/quote]
void zhucaodan()
{
    char c;
    system("cls");
    printf("\n\t\t|-------欢迎您使用通讯录管理系统1.0beat版-----|");
    printf("\n\t\t|    1-添加联系人       2-查询和显示联系人");
    printf("\n\t\t|    3-删除联系人       4-修改联系人");
    printf("\n\t\t|    5-保存退出         6-不保存退出");
    printf("\n\t\t请选择您所所要的服务:");

    c = getch();

    switch(c){
    case '1':
        tianjia();
        break;

    case '2':
        chaxun();
        break;

    case '3':
        shanchu();
        break;

    case '4':
        xiugai();
        break;

    case '5':
        baocun();
        break;
    case '6':
        exit(0);

    default:
        zhucaodan();
    }
}
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

void tianjia()
{
printf("\n\t\t------------------ 请输入联系人信息 --------------------\n");
printf("\n\t\t输入联系人姓名:");
scanf("%s",txl[n].xingming); /*键盘输入*/
printf("\n\t\t输入联系人电话号码:");
scanf("%s",txl[n].dianhua);
printf("\n\t\t输入联系人地址:");
scanf("%s",txl[n].dizhi);
n++; /*统计个数*/
printf("\n\t\t是否继续添加联系人?(Y/N):"); /*是否继续输入联系人.*/
if (getch()=='y')
tianjia();
return;

}

[/quote] 在添加的.c文件中也加上 main.h的头文件 要不程序认不到你在main.h中定义的 “n”和“txl”
qq_41233302 2017-12-03
  • 打赏
  • 举报
回复
引用 9 楼 lzb4207123 的回复:
main.h头文件中改下
 struct  tongxunlu
{
//你的数据
};
extern struct tongxunlu txl[100];
extern int n;


main.c中
在int main()前加头文件后加上
struct  tongxunlu txl[100];
int n=0;


还是不行啊,大佬们,我想不通
lzb4207123 2017-12-03
  • 打赏
  • 举报
回复
引用 15 楼 qq_41233302 的回复:
[quote=引用 14 楼 lzb4207123 的回复:] 看了下 你的错误提示 你那里有用到 tianjia()这个函数吗 里面的报错是 在tianjia()中的
有的 tianjia是在zhucaodan里的[/quote] 把那部分代码贴出来一下 zhucaodan() 和 tianjia() 的
qq_41233302 2017-12-03
  • 打赏
  • 举报
回复
引用 14 楼 lzb4207123 的回复:
看了下 你的错误提示 你那里有用到 tianjia()这个函数吗 里面的报错是 在tianjia()中的
有的 tianjia是在zhucaodan里的
lzb4207123 2017-12-03
  • 打赏
  • 举报
回复

看了下 你的错误提示 你那里有用到 tianjia()这个函数吗
里面的报错是 在tianjia()中的
qq_41233302 2017-12-03
  • 打赏
  • 举报
回复
引用 11 楼 lzb4207123 的回复:
[quote=引用 10 楼 qq_41233302 的回复:] [quote=引用 9 楼 lzb4207123 的回复:] main.h头文件中改下
 struct  tongxunlu
{
//你的数据
};
extern struct  tongxunlu txl[100];
extern int n;
main.c中 在int main()前加头文件后加上
struct  tongxunlu txl[100];
int n=0;
还是不行啊,大佬们,我想不通 [/quote] 我这里用你上面的代码做了一个测试 main.h文件
#ifndef _MAIN_H_
#define _MAIN_H_

struct tongxunlu
{
	char xingming[20];
	char dianhua[20];
	char dizhi[40];
};


extern struct tongxunlu txl[100];
extern int n;

extern void zhucaodan();
extern void tianjia();
extern void baocun();
extern void chaxun();
extern void shancuo();
extern void xiugai();

#endif
main.c文件 其中你实现的其他功能代码不知道 所以void zhucaodan()中就只有打印 “THIS IS TEST”
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#define MAX_CUT 100

#include "./include/main.h"

struct tongxunlu txl[100];
int n = 0;

int main()
{
	
	system("cls");
	while(1)
	{
		zhucaodan();
	}
	
	return 0;
}


void zhucaodan()
{
printf("THIS IS TEST\n");	
fflush(stdout);
return;
}
文件结构如下:include文件中包含main.h文件 编译结构: 运行效果:因为你的循环中没有出口 标准输出不能显示 就在 打印后面加个一个刷新标准输出fflush(stdout) 可能是文件结构和你不一样 我main.c 使用的是 #include "./include/main.h" 而不是 #include "../include/main.h" [/quote] 我的就是将void zhucaodan再单独用一个.c文件写,然后它就抽风了 为什么呀???
qq_41233302 2017-12-03
  • 打赏
  • 举报
回复
我这里用你上面的代码做了一个测试 main.h文件
#ifndef _MAIN_H_
#define _MAIN_H_

struct tongxunlu
{
	char xingming[20];
	char dianhua[20];
	char dizhi[40];
};


extern struct tongxunlu txl[100];
extern int n;

extern void zhucaodan();
extern void tianjia();
extern void baocun();
extern void chaxun();
extern void shancuo();
extern void xiugai();

#endif
main.c文件 其中你实现的其他功能代码不知道 所以void zhucaodan()中就只有打印 “THIS IS TEST”
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#define MAX_CUT 100

#include "./include/main.h"

struct tongxunlu txl[100];
int n = 0;

int main()
{
	
	system("cls");
	while(1)
	{
		zhucaodan();
	}
	
	return 0;
}


void zhucaodan()
{
printf("THIS IS TEST\n");	
fflush(stdout);
return;
}
文件结构如下:include文件中包含main.h文件 编译结构: 运行效果:因为你的循环中没有出口 标准输出不能显示 就在 打印后面加个一个刷新标准输出fflush(stdout) 可能是文件结构和你不一样 我main.c 使用的是 #include "./include/main.h" 而不是 #include "../include/main.h" [/quote] 我的就是将void zhucaodan再单独用一个.c文件写,然后它就抽风了 为什么呀???
lzb4207123 2017-12-03
  • 打赏
  • 举报
回复
引用 10 楼 qq_41233302 的回复:
[quote=引用 9 楼 lzb4207123 的回复:]
main.h头文件中改下
 struct  tongxunlu
{
//你的数据
};
extern struct tongxunlu txl[100];
extern int n;


main.c中
在int main()前加头文件后加上
struct  tongxunlu txl[100];
int n=0;


还是不行啊,大佬们,我想不通
[/quote]

我这里用你上面的代码做了一个测试
main.h文件
#ifndef _MAIN_H_
#define _MAIN_H_

struct tongxunlu
{
char xingming[20];
char dianhua[20];
char dizhi[40];
};


extern struct tongxunlu txl[100];
extern int n;

extern void zhucaodan();
extern void tianjia();
extern void baocun();
extern void chaxun();
extern void shancuo();
extern void xiugai();

#endif


main.c文件 其中你实现的其他功能代码不知道 所以void zhucaodan()中就只有打印 “THIS IS TEST”
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>

#define MAX_CUT 100

#include "./include/main.h"

struct tongxunlu txl[100];
int n = 0;

int main()
{

system("cls");
while(1)
{
zhucaodan();
}

return 0;
}


void zhucaodan()
{
printf("THIS IS TEST\n");
fflush(stdout);
return;
}


文件结构如下:include文件中包含main.h文件


编译结构:

运行效果:因为你的循环中没有出口 标准输出不能显示 就在 打印后面加个一个刷新标准输出fflush(stdout)


可能是文件结构和你不一样 我main.c 使用的是 #include "./include/main.h" 而不是 #include "../include/main.h"
lzb4207123 2017-12-03
  • 打赏
  • 举报
回复
main.h头文件中改下
 struct  tongxunlu
{
//你的数据
};
extern struct  tongxunlu txl[100];
extern int n;
main.c中 在int main()前加头文件后加上
struct  tongxunlu txl[100];
int n=0;
qq_41233302 2017-12-02
  • 打赏
  • 举报
回复
引用 7 楼 atsillabkp 的回复:
感觉是main.h有问题,看看有没有 txl?

.h里是有的
哎,心态崩了
atsillabkp 2017-12-02
  • 打赏
  • 举报
回复
感觉是main.h有问题,看看有没有 txl?
  • 打赏
  • 举报
回复
引用 4 楼 qq_41233302 的回复:
[quote=引用 1 楼 lzb4207123 的回复:] 在实现文件中#include <stdio.h>
.c是有的 它就是不行 [/quote] 上一个路径下的include文件夹下面的math.h文件的第6行的txl出的问题
自信男孩 2017-12-02
  • 打赏
  • 举报
回复
缺少stdio.h头文件; 你需要保证每个.c文件里只要用到printf和scanf的,都引入stdio.h
qq_41233302 2017-12-02
  • 打赏
  • 举报
回复
引用 1 楼 lzb4207123 的回复:
在实现文件中#include <stdio.h>


.c是有的 它就是不行
heronism 2017-12-01
  • 打赏
  • 举报
回复
引用 1 楼 lzb4207123 的回复:
在实现文件中#include <stdio.h>
正解,不引用编译器会根据你的用法给它匹配一个原型,在某些时候(返回值大于等于2^31等情况)会出错的
棉猴 2017-12-01
  • 打赏
  • 举报
回复
txl变量没有定义
lzb4207123 2017-11-30
  • 打赏
  • 举报
回复
在实现文件中#include <stdio.h>

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧