错误日记:结构体结尾加分号
/*************************************************************************
> 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 1
typedef 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;
}