函数部分:
#include"head.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//结点数
int n;
//界面
void Interface()
{
printf("\n\n\n\n\t\t\t\t\t\t\t\t个人通讯录管理系统\n\n\n\n");
printf("\t\t\t\t\t\t\t\t 1.添加\n");
printf("\t\t\t\t\t\t\t\t 2.显示\n");
printf("\t\t\t\t\t\t\t\t 3.修改\n");
printf("\t\t\t\t\t\t\t\t 4.删除\n");
printf("\t\t\t\t\t\t\t\t 5.查找\n");
}
//建立动态链表存通讯录数据
struct Communication* creat(void)
{
struct Communication* head;
struct Communication* p1, * p2;
n = 0;
p1 = p2 = (struct Communication *)malloc(LEN);
printf("请输入人员信息\n");
printf("请输入姓名:");
scanf("%s", p1->name);
printf("%s", p1->name);
printf("请输入地址:");
scanf("%s", p1->address);
printf("请输入电话号码:");
scanf("%s", p1->num);
head = NULL;
while (p1->name[0]!='0')
{
n = n + 1;
if (n == 1)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
p1 = (struct Communication*)malloc(LEN);
printf("请输入姓名:");
scanf("%s", p1->name);
printf("请输入地址:");
scanf("%s", p1->address);
printf("请输入电话号码:");
scanf("%s", p1->num);
}
p2->next = NULL;
return(head);
}
//输出
void print(struct Communication* head)
{
struct Communication* p;
p = head;
if (head != NULL)
{
while (p != NULL)
{
printf("%d", n);
puts(p->name);
printf("\n");
puts(p->address);
printf("\n");
puts(p->num);
printf("\n");
p = p->next;
}
}
}
主函数部分:
#include<stdio.h>
#include"head.h"
#include<stdlib.h>
#include<string.h>
//建立动态链表存通讯录数据
struct Communication* creat(void);
//输出
void print(struct Communication* head);
//界面
void Interface();
int main()
{
struct Communication* pt;
Interface();
pt = creat();
print(pt);
return 0;
}
有error错误呢,编译都没通过,怎么会有exe文件生成呢,自然会提示没有exe文件来执行了
提示你有错误啊,根据提示修改代码,重新编译就是了
#pragma once
#define LEN sizeof(struct Communication)
//结点数
extern int n;
struct Communication
{
char name[10] ;
char address[20];
char num[11];
struct Communication* next;
};
修改完善如下,缺了结构体的定义,其他见注释,供参考:
//#include"head.h"
//#include<stdio.h>
//#include<stdlib.h>
//#include<string.h>
//主函数部分:
#include<stdio.h>
//#include"head.h"
#include<stdlib.h>
#include<string.h>
struct Communication{
char name[16];
char address[64];
char num[12];
struct Communication *next;
};
int n=0; //结点数
int LEN = sizeof(struct Communication);
struct Communication* creat(void);//建立动态链表存通讯录数据
void print(struct Communication* head);//输出
void Interface();//界面
int main()
{
struct Communication* pt;
Interface();
pt = creat();
print(pt);
return 0;
}
//界面
void Interface()
{
printf("\n\n\n\n\t\t\t\t\t\t个人通讯录管理系统\n\n\n\n");
printf("\t\t\t\t\t\t 1.添加\n");
printf("\t\t\t\t\t\t 2.显示\n");
printf("\t\t\t\t\t\t 3.修改\n");
printf("\t\t\t\t\t\t 4.删除\n");
printf("\t\t\t\t\t\t 5.查找\n");
}
//建立动态链表存通讯录数据
struct Communication* creat(void)
{
struct Communication* head;
struct Communication* p1, * p2;
//n = 0;
//p1 = p2 = (struct Communication *)malloc(LEN);
//printf("请输入人员信息\n");
//printf("请输入姓名:");
//scanf("%s", p1->name);
//printf("%s", p1->name);
//printf("请输入地址:");
//scanf("%s", p1->address);
//printf("请输入电话号码:");
//scanf("%s", p1->num);
head = NULL;
while (1)
{
p1 = (struct Communication*)malloc(LEN);
printf("请输入姓名:");
scanf("%s", p1->name);
if(strcmp(p1->name,"0")==0) break; //输入“0”,结束输入
printf("请输入地址:");
scanf("%s", p1->address);
printf("请输入电话号码:");
scanf("%s", p1->num);
n = n + 1;
if (n == 1)
{
head = p1;
}
else
{
p2->next = p1;
}
p2 = p1;
}
free(p1);
return(head);
}
//输出
void print(struct Communication* head)
{
struct Communication* p;
p = head;
//if (head != NULL)
//{
while (p != NULL)
{
printf("%d\n", n);
puts(p->name);
//printf("\n");
puts(p->address);
//printf("\n");
puts(p->num);
printf("\n");
p = p->next;
}
//}
}