user-0 提问: c语言链表程序错误

回复:
user: user-0
content: 引用 7 楼 自信男孩的回复:[quote=引用 6 楼 Gnglas 的回复:] =  [quote=引用 4 楼 自信男孩 的回复:] #include<stdio.h> #include<stdlib.h> #include<string.h>  #pragma warning(disable : 4996) #define nuber 30 //题目：存储电影信息 typedef struct  _mv {     char mvname[nuber];     int rating;     struct _mv* next;                    //存储下一个节点的地址 }newmv;  char *s_gets(char* fp, int a);            //定义输入函数 void puts_s(struct _mv* p);  int main() {     newmv* head = NULL;     newmv* prev=NULL, * last=NULL;     char input[nuber];     puts("stdin mv the name");     while (s_gets(input,nuber)!=NULL&&input[0]!='\0')     {         prev = (struct _mv*)malloc(sizeof(struct _mv));         if(head==NULL)         {             head = prev;             last = head;    //link nodes             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             strcpy(prev->mvname, input);             getchar();    //for '\n'         }         else         {              strcpy(prev->mvname, input);             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             getchar();   //for '\n'             prev->next = NULL;             //link nodes             last->next = prev;             last = prev;         }         puts("stdin mv the name");     }     puts_s(head);//遍历链表，输出链表的内容 } void puts_s(struct _mv* phead) {     struct _mv *p = phead;     while (p != NULL)     {         printf("name:%s\tint:%d\n", p->mvname, p->rating);         p = p->next;     } }    //输入函数 char* s_gets(char* fp, int a) {     char* re=NULL, * find = NULL;     re = fgets(fp, a, stdin);     if (re)     {         find = strchr(fp, '\n');         if (find)             *find = '\0';         else             while (getchar() != '\n')             {                 continue;             }     }     return find; } 供参考～还有写链表，能不能，教我最重要的是什么[/quote] 最重要的是链表直接的链接以及关系～  链表是怎么链接起来的，为什么next就能找到下一个链表节点[/quote] 好的，我多练习练习       ，

user: user-1
content: 引用 6 楼 Gnglas 的回复:=  [quote=引用 4 楼 自信男孩 的回复:] #include<stdio.h> #include<stdlib.h> #include<string.h>  #pragma warning(disable : 4996) #define nuber 30 //题目：存储电影信息 typedef struct  _mv {     char mvname[nuber];     int rating;     struct _mv* next;                    //存储下一个节点的地址 }newmv;  char *s_gets(char* fp, int a);            //定义输入函数 void puts_s(struct _mv* p);  int main() {     newmv* head = NULL;     newmv* prev=NULL, * last=NULL;     char input[nuber];     puts("stdin mv the name");     while (s_gets(input,nuber)!=NULL&&input[0]!='\0')     {         prev = (struct _mv*)malloc(sizeof(struct _mv));         if(head==NULL)         {             head = prev;             last = head;    //link nodes             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             strcpy(prev->mvname, input);             getchar();    //for '\n'         }         else         {              strcpy(prev->mvname, input);             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             getchar();   //for '\n'             prev->next = NULL;             //link nodes             last->next = prev;             last = prev;         }         puts("stdin mv the name");     }     puts_s(head);//遍历链表，输出链表的内容 } void puts_s(struct _mv* phead) {     struct _mv *p = phead;     while (p != NULL)     {         printf("name:%s\tint:%d\n", p->mvname, p->rating);         p = p->next;     } }    //输入函数 char* s_gets(char* fp, int a) {     char* re=NULL, * find = NULL;     re = fgets(fp, a, stdin);     if (re)     {         find = strchr(fp, '\n');         if (find)             *find = '\0';         else             while (getchar() != '\n')             {                 continue;             }     }     return find; } 供参考～还有写链表，能不能，教我最重要的是什么[/quote] 最重要的是链表直接的链接以及关系～  链表是怎么链接起来的，为什么next就能找到下一个链表节点

user: user-0
content: =  引用 4 楼 自信男孩 的回复:#include<stdio.h> #include<stdlib.h> #include<string.h>  #pragma warning(disable : 4996) #define nuber 30 //题目：存储电影信息 typedef struct  _mv {     char mvname[nuber];     int rating;     struct _mv* next;                    //存储下一个节点的地址 }newmv;  char *s_gets(char* fp, int a);            //定义输入函数 void puts_s(struct _mv* p);  int main() {     newmv* head = NULL;     newmv* prev=NULL, * last=NULL;     char input[nuber];     puts("stdin mv the name");     while (s_gets(input,nuber)!=NULL&&input[0]!='\0')     {         prev = (struct _mv*)malloc(sizeof(struct _mv));         if(head==NULL)         {             head = prev;             last = head;    //link nodes             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             strcpy(prev->mvname, input);             getchar();    //for '\n'         }         else         {              strcpy(prev->mvname, input);             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             getchar();   //for '\n'             prev->next = NULL;             //link nodes             last->next = prev;             last = prev;         }         puts("stdin mv the name");     }     puts_s(head);//遍历链表，输出链表的内容 } void puts_s(struct _mv* phead) {     struct _mv *p = phead;     while (p != NULL)     {         printf("name:%s\tint:%d\n", p->mvname, p->rating);         p = p->next;     } }    //输入函数 char* s_gets(char* fp, int a) {     char* re=NULL, * find = NULL;     re = fgets(fp, a, stdin);     if (re)     {         find = strchr(fp, '\n');         if (find)             *find = '\0';         else             while (getchar() != '\n')             {                 continue;             }     }     return find; } 供参考～还有写链表，能不能，教我最重要的是什么

user: user-0
content: 引用 4 楼 自信男孩 的回复:#include<stdio.h> #include<stdlib.h> #include<string.h>  #pragma warning(disable : 4996) #define nuber 30 //题目：存储电影信息 typedef struct  _mv {     char mvname[nuber];     int rating;     struct _mv* next;                    //存储下一个节点的地址 }newmv;  char *s_gets(char* fp, int a);            //定义输入函数 void puts_s(struct _mv* p);  int main() {     newmv* head = NULL;     newmv* prev=NULL, * last=NULL;     char input[nuber];     puts("stdin mv the name");     while (s_gets(input,nuber)!=NULL&&input[0]!='\0')     {         prev = (struct _mv*)malloc(sizeof(struct _mv));         if(head==NULL)         {             head = prev;             last = head;    //link nodes             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             strcpy(prev->mvname, input);             getchar();    //for '\n'         }         else         {              strcpy(prev->mvname, input);             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             getchar();   //for '\n'             prev->next = NULL;             //link nodes             last->next = prev;             last = prev;         }         puts("stdin mv the name");     }     puts_s(head);//遍历链表，输出链表的内容 } void puts_s(struct _mv* phead) {     struct _mv *p = phead;     while (p != NULL)     {         printf("name:%s\tint:%d\n", p->mvname, p->rating);         p = p->next;     } }    //输入函数 char* s_gets(char* fp, int a) {     char* re=NULL, * find = NULL;     re = fgets(fp, a, stdin);     if (re)     {         find = strchr(fp, '\n');         if (find)             *find = '\0';         else             while (getchar() != '\n')             {                 continue;             }     }     return find; } 供参考～输入程序照搬的，实在没怎么看懂，能讲解一下吗

user: user-1
content: #include<stdio.h> #include<stdlib.h> #include<string.h>  #pragma warning(disable : 4996) #define nuber 30 //题目：存储电影信息 typedef struct  _mv {     char mvname[nuber];     int rating;     struct _mv* next;                    //存储下一个节点的地址 }newmv;  char *s_gets(char* fp, int a);            //定义输入函数 void puts_s(struct _mv* p);  int main() {     newmv* head = NULL;     newmv* prev=NULL, * last=NULL;     char input[nuber];     puts("stdin mv the name");     while (s_gets(input,nuber)!=NULL&&input[0]!='\0')     {         prev = (struct _mv*)malloc(sizeof(struct _mv));         if(head==NULL)         {             head = prev;             last = head;    //link nodes             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             strcpy(prev->mvname, input);             getchar();    //for '\n'         }         else         {              strcpy(prev->mvname, input);             printf("stdin (0-9)");             scanf_s("%d", &prev->rating);             getchar();   //for '\n'             prev->next = NULL;             //link nodes             last->next = prev;             last = prev;         }         puts("stdin mv the name");     }     puts_s(head);//遍历链表，输出链表的内容 } void puts_s(struct _mv* phead) {     struct _mv *p = phead;     while (p != NULL)     {         printf("name:%s\tint:%d\n", p->mvname, p->rating);         p = p->next;     } }    //输入函数 char* s_gets(char* fp, int a) {     char* re=NULL, * find = NULL;     re = fgets(fp, a, stdin);     if (re)     {         find = strchr(fp, '\n');         if (find)             *find = '\0';         else             while (getchar() != '\n')             {                 continue;             }     }     return find; } 供参考～

user: user-0

user: user-0
content: 而且还有乱码