user-0 提问: 不知道哪里错了

回复:
user: user-1
content: #include <stdio.h> #include <malloc.h> //#include "stdio.h" //#include "malloc.h"  #define H sizeof(Node) typedef int ElemType;  typedef struct Node {     ElemType data;     struct Node* next; }Node;  typedef struct Node* linklist;  int n=0;  linklist creat(linklist head) {     int i;     linklist p1,p2;     head=(linklist)malloc(H);     //head = NULL;    /* remove this statement*/     p2 = head;     scanf("%d",&i);     while(i!=0)     {         p1=(linklist)malloc(H);         p1->data=i;         p2->next=p1;         p2=p1;         n++;         scanf("%d",&i);      }     p2->next=NULL;      return head;    /*return header node */ }  void print(linklist head) {     linklist p;      if (!head) {         printf("The link is empty!\n");         return;     }      p = head->next;     while (p) {         printf("%d ",p->data);         p = p->next;     }     putchar(10);     /*        if(head!=NULL)        {        p=head->next;        for(;p!=NULL;p=p->next)        printf("%d ",p->data);        }        else        printf("NULL");        */ }  int search(linklist head) {     int i,j=1;     linklist p;     printf("Please input the data to be searched: ");     scanf("%d",&i);     if(i<1||i>n) {         printf("查找范围不合理");         return -1;     } else {         p = head->next;         while(p && j < i) {             p = p->next;             j++;         }         if (p)             printf("Your searched data is: %d\n", p->data);     }      return 0; }  linklist charu(linklist head) {     int i,j;     linklist p1,p2;     printf("Please input the data to be inserted: ");     scanf("%d",&i);     if(i<1||i > n)         printf("插入位置错误");     else     {         if(head==NULL)         {             p1=(linklist)malloc(H);             scanf("%d", &p1->data);    /* should add & */             head->next=p1;             p1->next=NULL;   /* = not == */         }         else         {             if(i==1)             {                 p2=head->next;                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 head->next=p1;                 p1->next=p2;              }             if(i<n)             {                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 p2=head;                 for(j=1;j<i;j++)                 {                     p2=p2->next;                 }                 p1->next=p2->next;                 p2->next=p1;             }             if(i==n)             {                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 p2=head;                 for(j=1;j<=i;j++)                 {                     p2=p2->next;                 }                 p2->next=p1;                 p1->next=NULL;             }         }         n++;     }      return head;  /* return header node */ }  linklist del(linklist head) {     int i,j;     linklist p1,p2;     if(!head) {         printf("NO STATISTIC DELATE\n");         return NULL;     }      printf("Please input the data to be deleted: ");     scanf("%d",&i);     if(i==1)     {         p2=head;         p1=head->next;         p2->next=p1->next;     }     if(i==n)     {         p2=head;         for(j=1;j<n;j++)         {             p2=p2->next;             p2->next=NULL;   /* = not == */         }     }     else     {         p2=head;         p1=head;         for(j=1;j<n;j++)         {             p2=p2->next;          }         for(j=1;j<=n+1;j++)         {             p1=p1->next;         }         p2->next=p1;     }     n--;      return head; }  int main(void) {     linklist head = NULL;     head=creat(head);     print(head);     search(head);     head=charu(head);     print(head);     head=del(head);     print(head);      return 0; }  删除操作没有将删除之后的节点free掉会导致内存泄露，因此还需要优化一下；

user: user-1
content: #include <stdio.h> #include <malloc.h> //#include "stdio.h" //#include "malloc.h"  #define H sizeof(Node) typedef int ElemType;  typedef struct Node {     ElemType data;     struct Node* next; }Node;  typedef struct Node* linklist;  int n=0;  linklist creat(linklist head) {     int i;     linklist p1,p2;     head=(linklist)malloc(H);     //head = NULL;    /* remove this statement*/     p2 = head;     scanf("%d",&i);     while(i!=0)     {         p1=(linklist)malloc(H);         p1->data=i;         p2->next=p1;         p2=p1;         n++;         scanf("%d",&i);      }     p2->next=NULL;      return head;    /*return header node */ }  void print(linklist head) {     linklist p;      if (!head) {         printf("The link is empty!\n");         return;     }      p = head->next;     while (p) {         printf("%d ",p->data);         p = p->next;     }     putchar(10);     /*     if(head!=NULL)     {         p=head->next;         for(;p!=NULL;p=p->next)             printf("%d ",p->data);     }     else         printf("NULL");         */ }  int search(linklist head) {     int i,j=1;     linklist p;     printf("Please input your searching data: ");     scanf("%d",&i);     if(i<1||i>n)         printf("查找范围不合理");     else     {         p=head->next;         while(p!=NULL&&j<i)         {             p=p->next;             j++;         }         printf("%d",p->data);      }      return 0; }  linklist charu(linklist head) {     int i,j;     linklist p1,p2;     printf("Please input your inserting data: ");     scanf("%d",&i);     if(i<1||i>n)         printf("插入位置错误");     else     {         if(head==NULL)         {             p1=(linklist)malloc(H);             scanf("%d", &p1->data);    /* should add & */             head->next=p1;             p1->next=NULL;   /* = not == */         }         else         {             if(i==1)             {                 p2=head->next;                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 head->next=p1;                 p1->next=p2;              }             if(i<n)             {                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 p2=head;                 for(j=1;j<i;j++)                 {                     p2=p2->next;                 }                 p1->next=p2->next;                 p2->next=p1;             }             if(i==n)             {                 p1=(linklist)malloc(H);                 scanf("%d", &p1->data);    /* should add & */                 p2=head;                 for(j=1;j<=i;j++)                 {                     p2=p2->next;                 }                 p2->next=p1;                 p1->next=NULL;             }         }         n++;     }      return head;  /* return header node */ }  linklist del(linklist head) {     int i,j;     linklist p1,p2;     printf("Please input your deleting data: ");     scanf("%d",&i);     if(head==NULL)         printf("NO STATISTIC DELATE");     else     {         if(i==1)         {             p2=head;             p1=head->next;             p2->next=p1->next;         }         if(i==n)         {             p2=head;             for(j=1;j<n;j++)             {                 p2=p2->next;                 p2->next=NULL;   /* = not == */             }         }         else         {             p2=head;p1=head;             for(j=1;j<n;j++)             {                 p2=p2->next;              }             for(j=1;j<=n+1;j++)             {                 p1=p1->next;             }             p2->next=p1;         }         n--;     }      return head; }  int main(void) {     linklist head = NULL;     head=creat(head);     print(head);     search(head);     head=charu(head);     print(head);     head=del(head);     print(head);      return 0; }  有多处错误，有些编译器应该已经提示警告了。所以对于警告信息不要放过； 主要是语法错误；scanf输入第二个参数应该是地址，因此应该加& 函数需要返回链表头，但是却没有返回；