c语言typedef应用错误

//加盟会员管理系统
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Member
{
    char num[100];//会员编号牌
    char name[15];//姓名
    char title[20];//会长,副会长,高级会员,普通会员
    char sex[20];//性别
    char age[20];//年龄
    char telephone[20];//电话
    struct Member *next;
};
typedef struct Member Node;
typedef struct Member *Link;

void Menu();//主函数及主界面
void Insert(Link head);//插入功能
void Delete(Link head);//删除功能
void Modify(Link head);//修改功能
void Query(Link head);//查询功能
void Save(Link head);//保存功能
void Load(Link head);//载入功能


void main ()//主函数
{
    Node head;
    void Menu(Link head);
}


void Menu(Link head)//菜单
{
    int choice;
    do{
        printf("1:Insert\n2:Delete\n3:Modify\n4:Query\n5:Save6\n:Load\n0:Exit\n");
        scanf("%d", &choice);
        switch(choice)
        {
        case 1:Insert(Link head);break;
        case 2:Delete(Link head);break;
        case 3:Modify(Link head);break;
        case 4:Query(Link head);break;
        case 5:Save(Link head);break;
        case 6:Load(Link head);break;
        case 0:break;
        }
    }while(choice!=0);
}


void Insert(Link head)//插入
{
    Node z;
    int choice=1;
    if(choice==1)
    {
        scanf("%s,%s,%s,%s,%s,%s",&z->num,&z->name,&z->title,&z->sex,&z->age,&z->telephone);
        z->next=head->next;
        head->next=*z;
        printf("1:Go on 0:Return menu\n");
        scanf("%d",&choice);
    }
    if(choice==0)
    {
        void Menu(Link head);
    }
}


void Delete(Link head)//删除
{
    char num[100];
    int judge=1;
    int choice=1
    Node p1=head->next;
    Node p2=head;
    if(choice=1)
    {
        printf("Please Enter Num\n");
        scanf("%s",&num);
        while(p != NULL)
        {
            p1=p1->next;
            p2=p2->next;
            if(num==p1->num)
            {
                if(p1->next != NULl)
                {
                    p2->next=p1->nxet;
                    free(p1);
                    printf("Successfully delete\n");
                }
                if(p1->next==NULL)
                {
                    p2->next=NULL;
                    printf("Successfully delete\n");
                }
                judge=0;
            }
        }
        if(judge=1)
            printf("No information found\nFail to delete\n");
        printf("1:Go on 0:Return menu\n");
        scanf("%d",&choice);
    }
    if(choice=0)
        void Menu(Link head);
}

void Modify(Link head)//修改
{
    char num[100],name[15],title[20],sex[20],age[20],telephone[20];
    int choice=1;
    int date;
    if(choice=1)
    {
        printf("Please enter the modified number\n");
        scanf("%s",num);
        while(p != NULL)
        {
           p=p->next;
           if(num==p->num)
           {
               printf("%s,%s,%s,%s,%s,%s\n",p->num,p->name,p->title,p->sex,p->age,p->telephone);
               judge=0;
               printf("Please enter the modified data\n");
               printf("1:num 2:name 3:tetle 4:sex 5:age 6:telephone 0:cancel the change\n");
               scanf("%d",&date);
               printf("Please information\n");
               switch(date)
               {
               case 1:scanf("%s",&num);p->num=num;break;
               case 2:scanf("%s",&name);p->name=name;break;
               case 3:scanf("%s",&title);p->title=title;break;
               case 4:scanf("%s",&sex);p->sex=sex;break;
               case 5:scanf("%s",&age);p->age=age;break;
               case 6:scanf("%s",&telephone);p->telephone=telephone;break;
               case 0:break;
               }
            }
        }
        if(judge=1)
            printf("No information found\n");
        printf("1:Go On 0:Return Menu\n");
        scanf("%d",&choice);
    }
    if(choice=0)
        void Menu(Link head);
}
void Query(Link head)//查询
{
    char num[100];
    int judge=1;
    int choice=1
    Node p=head;
    if(choice=1)
    {
        printf("Please Enter Num\n");
        scanf("%s",&num);
        while(p != NULL)
        {
            p=p->next;
            if(num==p->num)
            {
                printf("%s,%s,%s,%s,%s,%s\n",p->num,p->name,p->title,p->sex,p->age,p->telephone);
                judge=0;
            }
        }
        if(judge=1)
            printf("No information found\n");
        printf("1:Go On 0:Return Menu\n");
        scanf("%d",&choice);
    }
    if(choice=0)
        void Menu(Link head);
}
 

调用Menu函数的时候不需要把这个函数的返回值类型也带上,void是多余的:

  • ` void Menu(Link head);` 应该改为 `Menu(&head);`

 

结构体作为参数的时候,也不需要把类型带上,只需要变量名即可,所以:

  • 调用的地方,` void Menu(Link head);` 应该改为:` Menu(&head);`
  • 同理,调用的地方,`case 1:Insert(Link head);break; ` 应该改为 `case 1:Insert(head);break;`
  • 其他同理

 

要区分指针和非指针:

  • main函数里定义了 `Node head; ` ,这里的 head 变量类型是 Node,也就是 `typedef struct Member Node;` 也就是 `struct Member;` 类型,那么 head 不是指针,而 Menu 函数需要的是 Link=`typedef struct Member* Link;` 类型,是一个 `struct Member* ` 类型,因此你需要传入 &head 类型才对。通过 & 操作符取变量 head 的指针。
  • 同理,Insert 函数里的  `Node z;` z也不是个指针,你应该在堆上分配一个对象,例如 `Link z = (Link)malloc(sizeof(struct Member));` 

 

scanf 写字符串指针的问题:

  • 例如 Insert 里面,`scanf("%s,%s,%s,%s,%s,%s",&z->num,&z->name,&z->title,&z->sex,&z->age,&z->telephone);` 这里 name/tile/sex/age/telephone 都是 char 数组,数组名字就是指针,因此作为 scanf 的参数时,不必再用 & 操作符取指针地址,否则变成指针的指针。
  • 应该改为:`scanf("%s,%s,%s,%s,%s,%s", z->num, z->name, z->title, z->sex, z->age, z->telephone);`

 

最后,main 函数应该返回 int,修改为:

int main(){

  ...

  return 0;

}

 

看代码,可能你 C 语言的很多地方需要补。