user-0 提问: 新手！！链桟问题请大神求解！！

回复:
user: user-0
content: 引用 2 楼 cfjtaishan 的回复:#if 0 #include<stdio.h> #include<stdlib.h>  typedef struct car {     int id;     char color[20]; }CAR;  typedef struct node {     CAR data;     struct node *next; }NODE;  int main(void) {      NODE *top;     top = NULL;      //加入节点，入栈     NODE *p; //定义指针     p = (NODE *)malloc(sizeof(NODE)); //分配空间     p->data.id=12345; //赋值     p->next = NULL;      NODE *q;     q=(NODE *)malloc(sizeof(NODE));     q->data.id=23456;     q->next = NULL;      NODE *s;     s=(NODE *)malloc(sizeof(NODE));     s->data.id = 34567;     s->next = NULL;      p->next = top;     top = p;      q->next = top;     top = q;      s->next = top;     top = s;      //输出     NODE *t;     t = top;     while(t)     {         printf("%d\n",t->data.id);         t = t->next;     }      //删除     NODE *tmp;     tmp = top;     top = top->next;     if (tmp)         free(tmp); //释放内存      //输出     NODE *t1;     t1 = top;     printf("删除\n");     while(t1)     {         printf("%d\n",t1->data.id);         t1 = t1->next;     }  }  #else  //现要求对上面的代码改为在函数中实现  //下面的是我修改的，出现的语法错误，本人刚入门，请大神指点一二，万分感激  #include<stdio.h> #include<stdlib.h> #include <string.h>  typedef struct car {     int id;     char color[20]; }CAR;  typedef struct node {     CAR data;     struct node *next; }NODE;  void initLinkStack(NODE **top) {     *top = NULL; }  void insertLinkStack(NODE **top,CAR newCar) {     NODE *node;      node = (NODE *)malloc(sizeof(NODE));     if (!node)         exit(0);      node->data = newCar;     node->next = *top;     *top = node; }  void outPutLinkStack(NODE *top) {     NODE *t;      t = top;     while (t) {         printf("车牌：%d ,颜色：%s\n",t->data.id,t->data.color);         t = t->next;     } }  void deleteLinkStack(NODE **top) {     NODE *tmp;      if (!top)         return;     tmp = *top;     *top = (*top)->next;     free(tmp); //释放内存  }  int main() {     CAR C1 = {123456,"black"};     CAR C2 = {234567,"blue"};     CAR C3 = {345678,"red"};      NODE *top; //定义栈顶指针     initLinkStack(&top);      //增加元素     printf("依次增加桟元素:\n");     insertLinkStack(&top,C1);     insertLinkStack(&top,C2);     insertLinkStack(&top,C3);     //输出元素     outPutLinkStack(top);      //删除元素     printf("删除栈顶元素:\n");     deleteLinkStack(&top);     //输出元素     outPutLinkStack(top);  } #endif 修改你的代码之后，可以试一下；  NODE top; //定义栈顶指针 initLinkStack(&top); 注释和你的实际不相符，比如上面的两句代码，注释是定义栈顶指针，但是，却是定义了一个结构体变量，而非指针。  谢谢啦

user: user-0
content: 引用 1 楼 user-2 的回复:并没有语法错误。 main函数需要返回int  我用无返回类型的呢，我直接用指针传值的

user: user-0
content: 谢谢大家！！！

user: user-1
content: #include<stdio.h> #include<stdlib.h> #include <string.h>   typedef struct car {     int id;     char color[20]; }CAR;   typedef struct node {     CAR data;     struct node *next; }NODE;   void initLinkStack(NODE **top) {     *top = NULL; }   void insertLinkStack(NODE **top,CAR newCar) {     NODE *node;       node = (NODE *)malloc(sizeof(NODE));     if (!node)         exit(0);       node->data = newCar;     node->next = *top;     *top = node; }   void outPutLinkStack(NODE *top) {     NODE *t;       t = top;     while (t) {         printf("车牌：%d ,颜色：%s\n",t->data.id,t->data.color);         t = t->next;     } }   void deleteLinkStack(NODE **top) {     NODE *tmp;       if (!top)         return;     tmp = *top;     *top = (*top)->next;     free(tmp); //释放内存   }   int main() {     CAR C1 = {123456,"black"};     CAR C2 = {234567,"blue"};     CAR C3 = {345678,"red"};       NODE *top; //定义栈顶指针     initLinkStack(&top);       //增加元素     printf("依次增加桟元素:\n");     insertLinkStack(&top,C1);     insertLinkStack(&top,C2);     insertLinkStack(&top,C3);     //输出元素     outPutLinkStack(top);       //删除元素     printf("删除栈顶元素:\n");     deleteLinkStack(&top);     //输出元素     outPutLinkStack(top);   }

user: user-1
content: #if 0 #include<stdio.h> #include<stdlib.h>  typedef struct car {     int id;     char color[20]; }CAR;  typedef struct node {     CAR data;     struct node *next; }NODE;  int main(void) {      NODE *top;     top = NULL;      //加入节点，入栈     NODE *p; //定义指针     p = (NODE *)malloc(sizeof(NODE)); //分配空间     p->data.id=12345; //赋值     p->next = NULL;      NODE *q;     q=(NODE *)malloc(sizeof(NODE));     q->data.id=23456;     q->next = NULL;      NODE *s;     s=(NODE *)malloc(sizeof(NODE));     s->data.id = 34567;     s->next = NULL;      p->next = top;     top = p;      q->next = top;     top = q;      s->next = top;     top = s;      //输出     NODE *t;     t = top;     while(t)     {         printf("%d\n",t->data.id);         t = t->next;     }      //删除     NODE *tmp;     tmp = top;     top = top->next;     if (tmp)         free(tmp); //释放内存      //输出     NODE *t1;     t1 = top;     printf("删除\n");     while(t1)     {         printf("%d\n",t1->data.id);         t1 = t1->next;     }  }  #else  //现要求对上面的代码改为在函数中实现  //下面的是我修改的，出现的语法错误，本人刚入门，请大神指点一二，万分感激  #include<stdio.h> #include<stdlib.h> #include <string.h>  typedef struct car {     int id;     char color[20]; }CAR;  typedef struct node {     CAR data;     struct node *next; }NODE;  void initLinkStack(NODE **top) {     *top = NULL; }  void insertLinkStack(NODE **top,CAR newCar) {     NODE *node;      node = (NODE *)malloc(sizeof(NODE));     if (!node)         exit(0);      node->data = newCar;     node->next = *top;     *top = node; }  void outPutLinkStack(NODE *top) {     NODE *t;      t = top;     while (t) {         printf("车牌：%d ,颜色：%s\n",t->data.id,t->data.color);         t = t->next;     } }  void deleteLinkStack(NODE **top) {     NODE *tmp;      if (!top)         return;     tmp = *top;     *top = (*top)->next;     free(tmp); //释放内存  }  int main() {     CAR C1 = {123456,"black"};     CAR C2 = {234567,"blue"};     CAR C3 = {345678,"red"};      NODE *top; //定义栈顶指针     initLinkStack(&top);      //增加元素     printf("依次增加桟元素:\n");     insertLinkStack(&top,C1);     insertLinkStack(&top,C2);     insertLinkStack(&top,C3);     //输出元素     outPutLinkStack(top);      //删除元素     printf("删除栈顶元素:\n");     deleteLinkStack(&top);     //输出元素     outPutLinkStack(top);  } #endif 修改你的代码之后，可以试一下；  NODE top; //定义栈顶指针 initLinkStack(&top); 注释和你的实际不相符，比如上面的两句代码，注释是定义栈顶指针，但是，却是定义了一个结构体变量，而非指针。

user: user-2
content: 并没有语法错误。 main函数需要返回int