本系统是用纯c语言写的通讯录系统,主要涉及的是单链表的增加节点,删除节点,查询节点等,还有文件的读写。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//定义结构体
typedef struct Info{
char name[20];//姓名
char telphone[20];//电话
char city[20];//城市
char province[20];//省份
char country[20];//国家
};
//结点
typedef struct Node{
struct Info data;
struct Node *next;
}Node,*LinkNode;
/*
判断数组是否越界
*/
void stringInput(char *c,int n,char *input){
char s[50];
do{
printf(input);
scanf("%s",s);
if (strlen(s) > n)
printf("输入的字符超过指定的长度,请重新输入\n");
} while (strlen(s) > n);
strcpy(c,s);
}
/*
插入记录
*/
void enter(LinkNode l)
{
Node *p, *q;//q代表头结点,p带表要插入的结点
q = l ;
while (1)
{
p = (LinkNode)malloc(sizeof(Node));
if (!p)
{
printf("系统分配内存空间失败\n");
return;
}
stringInput(p->data.name,20,"请输入姓名:\n")