链表出错

来源:百度知道 编辑:UC知道 时间:2024/06/15 15:09:13
输入和输出链表,但是能输入,输出不了:
错误信息如下:1.第36行:incompatible types - from 'struct $S1 *' to 'struct goods *'
2.第49行:warning C4133: 'function' : incompatible types - from 'struct goods *' to 'struct $S1 *'

代码如下:
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct goods)
struct goods
{
int codeID;
char name[50];
int mount;
struct goods *next;
};
int n;
struct goods *createlist(void)
{
struct goods *head;
struct goods *p1,*p2;
n=0;
p1=p2=(struct goods*)malloc(LEN);
scanf("%ld,%s,%d",&p1->codeID,p1->name,&p1->mount);
head=NULL;
while (p1->codeID!=0)
{
n=n+1;
if(n==1) head=p1;
else p2->next=p1;
p2=p1;
p1=(struct goods*)malloc(LEN);
scanf("%ld,%s,%d",&p1->codeID,p1->name,&p1->mount);
}
p2->next=NULL;

那个函数这样改:void list(struct goods *head) 加上一个goods

还有建立链表的时候两个输入语句这样改:
scanf("%ld",&p1->codeID);
getchar();
scanf("%s",p1->name);
getchar();
scanf("%d",&p1->mount);