通讯录1.0(可实现插入输出)
来源:互联网 发布:freebsd和centos 编辑:程序博客网 时间:2024/06/03 10:40
错误日记:结构体结尾加分号
/************************************************************************* > File Name: Address_list.c > Author: ma6174 > Mail: ma6174@163.com > Created Time: 2017年05月23日 星期二 11时19分25秒 ************************************************************************/#include<stdio.h>#include<stdlib.h>#include<string.h>#define F -1#define T 1typedef struct Address addr;typedef struct Node* node;typedef int type;struct Address{type id;char num[15];char name[15];char address[100];};struct Node//单链表{struct Node *next;addr data;};int init(node*);//初始化int interface(void);//功能列表type insert_tail(node);//从尾部插入int insert_id(node, int*);//由id插入void print(node head);//打印int main(){node head;int ret = 0;int n = 0;int n1 = 0;init(&head);for(;ret != 8;){ret = interface();switch(ret){case 1:printf("how many contacts you want to put in?\n");scanf("%d", &n);n1 = n;for(;n1 > 0; n1--){insert_tail(head);}break;case 2:insert_id(head, &n);printf("%d", n);break;case 7:print(head);break;case 8:break;default:printf("Warning:wrong function!\n");break;}}return 0;}int init(node* head){node newnode = (node)malloc(sizeof(struct Node));if(newnode == NULL){return F;}newnode->next = NULL;newnode->data.id = 0;strcpy(newnode->data.name, "name") ;strcpy(newnode->data.num, "number") ;strcpy(newnode->data.address, "address");*head = newnode;return T;}int interface(void){int flag = F;printf("Welcome To Use Address_list System\n");printf("1.Add contacts in batch\n");printf("2.Add a contact\n");printf("3.Delete a contact\n");printf("4.Edit a contact\n");printf("5.Find a contact\n");printf("6.Sort\n");printf("7.Print Address_list\n");printf("8.QUIT\n");scanf("%d", &flag);return flag;}type insert_tail(node head){int i = 1;char s1[15];char s2[15];char s3[100];node newnode = (node)malloc(sizeof(struct Node));if(newnode == NULL){return F;}newnode->next = NULL;while(head->next != NULL){head = head->next;i++;}head->next = newnode;newnode->data.id = i;printf("id NO.%d\n", i);printf("please input name\n");scanf("%s", s1);printf("please input num\n");scanf("%s", s2);printf("please input address\n");scanf("%s", s3);strcpy(newnode->data.name, s1);strcpy(newnode->data.num, s2);strcpy(newnode->data.address, s3);return T;}void print(node head){while(head->next != NULL){ printf("%d %15s %15s %15s\n", head->data.id, head->data.name, head->data.num, head->data.address);head = head->next;} printf("%d %15s %15s %15s\n", head->data.id, head->data.name, head->data.num, head->data.address);printf("\n\n\n");}int insert_id(node head, int* n){int i = 1;char s1[15];char s2[15];char s3[100];int f = 0;if(0 == *n){printf("you can't add contact to a empty Address_list\n");printf("please choose 1\n");printf("\n");printf("\n");return F;}node newnode = (node)malloc(sizeof(struct Node));if(newnode == NULL){return F;}for(;f == 0;){printf("The id of this contact\n");scanf("%d", &i);if(i > *n + 1|| i < 1){printf("illegal id!\n");}else{newnode->data.id = i;printf("please input name\n");scanf("%s", s1);printf("please input num\n");scanf("%s", s2);printf("please input address\n");scanf("%s", s3);strcpy(newnode->data.name, s1);strcpy(newnode->data.num, s2);strcpy(newnode->data.address, s3);f = 1;++*n;}}for(f = 1; f < i; f++){head = head->next;}newnode->next = head->next;head->next = newnode;printf("%d\n", head->data.id);head = newnode;while(head->next != NULL){head = head->next;head->data.id++;}return T;}
阅读全文
0 0
- 通讯录1.0(可实现插入输出)
- 【通讯录系统】:实现一个通讯录(可添加、删除、修改、查找、显示、清空、排序)
- 编写一个可容纳1000人的通讯录(【结构体】静态通讯录的实现)
- Java检测插入可移动磁盘实现
- 通讯录(二)----动态实现
- 通讯录(三)----文件实现
- Python实现通讯录(1)
- 通讯录2.0(动态实现)
- 通讯录数据库插入数据
- Android 自定义 View 实现通讯录字母索引(仿微信通讯录)
- 实现动态版本通讯录(在简易通讯录的基础上)
- Android 自定义 View 实现通讯录字母索引(仿微信通讯录)
- 实现通讯录
- 实现通讯录
- 实现通讯录
- 实现数组插入排序并输出
- 实现一个通讯录(数组实现)
- 通讯录的实现(动态实现)
- 使用网络技术————新闻客户端
- poj1753之DFS
- 【2013年第四届蓝桥杯C/C++程序设计本科B组决赛 连续奇数和(结果填空) 】
- C
- 二叉树
- 通讯录1.0(可实现插入输出)
- ChannelPipeline
- 计算几何资料(不定时更新)
- win7远程桌面连接Ubuntu 14.04
- 总结(一)
- java多种方式实现1G文件复制
- 最好 FFmpeg 给视频 添加水印 添加标注
- 寄语
- 找出数组中每个数的右边第一个比它大的数