想要将商品信息读入链表中,但编译发生错误,求解;
代码如下:
```#include<stdio.h>
#include<stdlib.h>
#define GOODS_FILE_NAME "goodsinfo.txt"
#define MAX_ID_LEN 30
#define MAX_NAME_LEN 30
#define MAX_PRICE_LEN 30
#define MAX_DISCOUNT_LEN 30
extern int CurrentCnt;
typedef struct {
char goods_id[MAX_ID_LEN];
char goods_name[MAX_NAME_LEN];
int goods_price;
char goods_discount[MAX_DISCOUNT_LEN];
int goods_amount;
int goods_remain;
} GoodsInfo;
typedef struct node
{
GoodsInfo data;
struct node *next;
} GoodsList;
int main ()
{
GoodsList **L;
GoodsInfo info;
GoodsList *head_list=(GoodsList*)malloc(sizeof(GoodsList)),*p;
*L=head_list;
FILE *fp=fopen("goodsinfo.txt","r");
if(fp==NULL){
printf("error: file not found");
return 0;
}
else {
while(!feof(fp)) {
fscanf(fp,"%s%s%d%s%d%d",info.goods_id,info.goods_name,&(info.goods_price),info.goods_discount,&(info.goods_amount),&(info.goods_remain));
p=(GoodsList *)malloc(sizeof(GoodsList));
head_list->next=p;
head_list->data=info;
CurrentCnt++;
}
}
fclose(fp);
p->next=NULL;
printf("商品的链表文件已建立,有%d个商品记录\n", CurrentCnt);
}
编译错误如下:

供参考:
#include<stdio.h>
#include<stdlib.h>
#define GOODS_FILE_NAME "goodsinfo.txt"
#define MAX_ID_LEN 30
#define MAX_NAME_LEN 30
#define MAX_PRICE_LEN 30
#define MAX_DISCOUNT_LEN 30
extern int CurrentCnt;
typedef struct {
char goods_id[MAX_ID_LEN];
char goods_name[MAX_NAME_LEN];
int goods_price;
char goods_discount[MAX_DISCOUNT_LEN];
int goods_amount;
int goods_remain;
} GoodsInfo;
typedef struct node
{
GoodsInfo data;
struct node* next;
} GoodsList;
int main()
{
GoodsList* L = (GoodsList*)malloc(sizeof(GoodsList));
L->next = NULL;
GoodsInfo info;
GoodsList* head_list = L, * p;
FILE* fp = fopen("goodsinfo.txt", "r");
if (fp == NULL) {
printf("error: file not found");
return 0;
}
else {
while (!feof(fp)) {
fscanf(fp, "%s%s%d%s%d%d", info.goods_id, info.goods_name, &info.goods_price, info.goods_discount, &info.goods_amount, &info.goods_remain);
p = (GoodsList*)malloc(sizeof(GoodsList));
p->data = info;
p->next = NULL;
head_list->next = p;
head_list = p;
CurrentCnt++;
}
}
fclose(fp);
//p->next = NULL;
printf("商品的链表文件已建立,有%d个商品记录\n", CurrentCnt);
}
求大佬帮忙看一下,谢谢mom