只有第一个位置的数据,无法继续打印后面的数据


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
struct mm
{
int xh;
double a[5],b[5],c[5];
struct mm *next;
};
int main()
{
int i=0;
struct mm *p=NULL,*follow;

FILE*ph=fopen("GSE100541.txt","r");
while(1)
{
    p=(struct mm*)malloc(sizeof(struct mm));
    fscanf(ph,"%d",&(p->xh));
    if(i==0)
        follow=p;
    p->next=NULL;
    if(p->xh==1)
        break;
   for(int j=0;j<5;j++)
    fscanf(ph,"%lf%lf%lf",&(p->a[j]),&(p->b[j]),&(p->c[j]));
  ///printf("%d",p->xh);
   ///for(int j=0;j<5;j++)
    ///printf("\t%f\t%f\t%f",p->a[j],p->b[j],p->c[j]);
   ///printf("\n");
   p=p->next;
   i++;
}
fclose(ph);
while(follow!=NULL){
printf("%d\t",follow->xh);
follow=follow->next;
}
return 0;
}

#include <stdio.h>
#include <stdlib.h>

struct mm
{
    int xh;
    double a[5], b[5], c[5];
    struct mm *next;
};

int main()
{
    struct mm *p = NULL, *head = NULL, *tail = NULL;

    FILE *ph = fopen("GSE100541.txt", "r");
    while (1)
    {
        p = (struct mm *)malloc(sizeof(struct mm));
        fscanf(ph, "%d", &(p->xh));
        p->next = NULL;
        if (p->xh == 1)
        {
            free(p);
            break;
        }
        for (int j = 0; j < 5; j++)
            fscanf(ph, "%lf%lf%lf", &(p->a[j]), &(p->b[j]), &(p->c[j]));
        if (!head)
            head = p;
        if (tail)
            tail->next = p;
        tail = p;
    }
    fclose(ph);

    p = head;
    while (p)
    {
        printf("%d\t", p->xh);
        p = p->next;
    }

    while (head) {
        struct mm *p = head;
        head = head->next;
        free(p);
    }

    return 0;
}