fscanf读取文件出现乱码死循环

devc++ 中fscanf读取文件出现死循环乱码


```c
typedef struct Node{
    int code;//商品代码 
    char name[50];//商品名称 
    int num;   //总量
    int  price;//价格 
    int sold_num;//销售量 
    int remain_num;//库存量 
    int total;//销售额 
    struct Node *next;
}node;

```c
int readFile(Node *L){
    FILE *fpr=fopen("Goods.txt","r");
    node st;
    node *s;
    node *t=L;
    if(fpr==NULL){
        return 0;
    }else{
        //fcanf()
        while(fscanf(fpr,"&d %s %d %d %d %d %d",&st.code,st.name,&st.num,&st.price,&st.sold_num,&st.remain_num,&st.total)!=EOF){
        printf("&d %s %d %d %d %d %d\n",st.code,st.name,st.num,st.price,st.sold_num,st.remain_num,st.total);
        s=(node *)malloc(sizeof(node));
        *s=st;
        t->next=s;
        t=s;
        t->next=NULL;
        }
    }
    return 1;
}

别用fscanf读取二进制文件,用fread()或者实在要这样的话改成下面试下

int readFile(Node *L){
    FILE *fpr=fopen("Goods.txt","r");
    node st;
    node *s;
    node *t=L;
    if(fpr==NULL){
        return 0;
    }
    else
    {
        while(!feof(fpr))
        {
            //fcanf()
            int validint=fscanf(fpr,"&d %s %d %d %d %d %d",&st.code,st.name,&st.num,&st.price,&st.sold_num,&st.remain_num,&st.total;
            if(validint==0)
                fgetc(fpr);
            printf("&d %s %d %d %d %d %d\n",st.code,st.name,st.num,st.price,st.sold_num,st.remain_num,st.total);
            s=(node *)malloc(sizeof(node));
            *s=st;
            t->next=s;
            t=s;
            t->next=NULL;
            
        }
    }
    return 1;
}