user-0 提问: C语言链表问题

回复:
user: user-1
content: snode *node = (snode*)malloc(sizeof(snode));改： struct snode *node = (struct  snode*)malloc(sizeof(struct snode));

user: user-2
content: 引用 2 楼 flowkiller 的回复:[quote=引用 1 楼 自信男孩 的回复:] #include <stdio.h> #include <stdlib.h> #include <string.h> struct snode {     char * str;     struct snode *next; };  struct snode *snode_create(char *s) ; void snode_destroy(struct snode * s) ;  ----------------------------------------------- //snode.c #include <stdio.h> #include "snode.h" #include <string.h> #include <stdlib.h> struct snode *snode_create(char *s) {     snode *node = (snode*)malloc(sizeof(snode));     if (!node)         exit(0);     node->str = (char*)malloc(sizeof(char) * strlen(s)+1);    //注意给'\0'留个空间     if (!node->str)         exit(0);     strcpy(node->str, s);     node->next = NULL;     return node; }  void snode_destroy(struct snode * s) {     free(s->str);     free(s); }//; 供参考～  报错啦 [/quote]  #include <stdio.h> #include <stdlib.h> #include <string.h> struct snode {     char * str;     struct snode *next; };  struct snode *snode_create(char *s) ; void snode_destroy(struct snode * s) ;  ----------------------------------------------- //snode.c #include <stdio.h> #include "snode.h" #include <string.h> #include <stdlib.h> struct snode *snode_create(char *s) {     struct snode *node = (struct snode*)malloc(sizeof(struct snode));     if (!node)         exit(0);     node->str = (char*)malloc(sizeof(char) * strlen(s)+1);    //注意给'\0'留个空间     if (!node->str)         exit(0);     strcpy(node->str, s);     node->next = NULL;     return node; }  void snode_destroy(struct snode * s) {     free(s->str);     free(s); }//; 加上struct，C语言不支持只写结构体名。

user: user-0
content: 引用 1 楼 自信男孩 的回复:#include <stdio.h> #include <stdlib.h> #include <string.h> struct snode {     char * str;     struct snode *next; };  struct snode *snode_create(char *s) ; void snode_destroy(struct snode * s) ;  ----------------------------------------------- //snode.c #include <stdio.h> #include "snode.h" #include <string.h> #include <stdlib.h> struct snode *snode_create(char *s) {     snode *node = (snode*)malloc(sizeof(snode));     if (!node)         exit(0);     node->str = (char*)malloc(sizeof(char) * strlen(s)+1);    //注意给'\0'留个空间     if (!node->str)         exit(0);     strcpy(node->str, s);     node->next = NULL;     return node; }  void snode_destroy(struct snode * s) {     free(s->str);     free(s); }//; 供参考～  报错啦

user: user-2
content: #include <stdio.h> #include <stdlib.h> #include <string.h> struct snode {     char * str;     struct snode *next; };  struct snode *snode_create(char *s) ; void snode_destroy(struct snode * s) ;  ----------------------------------------------- //snode.c #include <stdio.h> #include "snode.h" #include <string.h> #include <stdlib.h> struct snode *snode_create(char *s) {     snode *node = (snode*)malloc(sizeof(snode));     if (!node)         exit(0);     node->str = (char*)malloc(sizeof(char) * strlen(s)+1);    //注意给'\0'留个空间     if (!node->str)         exit(0);     strcpy(node->str, s);     node->next = NULL;     return node; }  void snode_destroy(struct snode * s) {     free(s->str);     free(s); }//; 供参考～