|
[mw_shl_code=c,true]while (gets (input) != NULL && input[0] != '\0');[/mw_shl_code]
目测多了分号
[mw_shl_code=c,true]scanf ("%d", current -> rating);[/mw_shl_code]
取地址运算符掉了
修改后的代码:
[mw_shl_code=c,true]#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TSIZE 48
struct film
{
char title[TSIZE];
int rating;
struct film * next;
};
int main(void)
{
struct film * head = NULL;
struct film * prev = NULL, * current;
char input[TSIZE];
//收集并存储信息
puts("Enter first movie title: ");
while (gets (input) != NULL && input[0] != '\0')
{
current = (struct film *) malloc (sizeof (struct film));
if (head == NULL)
head = current;
else
prev -> next = current;
current -> next = NULL;
strcpy (current -> title, input);
puts ("Enter your rating(0~10): ");
scanf ("%d", ¤t -> rating);
while (getchar () != '\n')//输入空行退出
continue;
puts ("Enter next movie title (empty line to stop): ");
prev = current;
}
//给出电影列表
if (head == NULL)
printf ("No data enter.");
else
printf ("Here is the movie list:\n");
current = head;
while (current != NULL)
{
printf ("Movie: %s Rating: %d\n",current -> title, current -> rating);
current = current -> next;
}
//任务完成,释放内存
current = head;
while (current != NULL)
{
free (current);
current = current -> next;
}
printf ("Bye.\n");
system("pause");
return 0;
}[/mw_shl_code] |
|