69,373
社区成员
发帖
与我相关
我的任务
分享
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;
}
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”#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文件写,然后它就抽风了
为什么呀???#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文件写,然后它就抽风了
为什么呀???#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
#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;
}
struct tongxunlu
{
//你的数据
};
extern struct tongxunlu txl[100];
extern int n;
main.c中
在int main()前加头文件后加上
struct tongxunlu txl[100];
int n=0;