#include <stdio.h>
#include <stdlib.h>
 
struct lnode { 
          char name[10];
          int points;
          int expense;
          int income;
          struct lnode *next;
} ;
 
int main(void) {
 
    lnode *head, *tail,*p;
   
    
    head=NULL;
    tail=NULL;
    p=NULL;
    FILE *infile = fopen("c:/H7.txt", "r");
    
    if( infile == NULL ) return 1;

    while(!feof(infile))
    {
        lnode *newptr=(lnode *)malloc(sizeof(lnode));
        newptr->next=NULL;
        if (head == NULL) {
            head = newptr;
        } 
        else {   
            tail->next=newptr;
        }
        tail = newptr;
        
        fscanf(infile,"%s %d %d %d ", &tail->name,&tail->points,&tail->expense,&tail->income);  
        
        
    };
    
    p = head;
    while (p != NULL){
        printf("%s %d %d %d\n",p->name,p->points,p->expense,p->income);
            
        p = p->next;
    };

    //free memory
    p = head;
    while (p != NULL){
        free(p);
        p = p->next;
    };
    
    head=NULL;
    tail=NULL;
    p=NULL;
 
    system("pause");
    return 0;
}