fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct lnode {
  5. char name[10];
  6. int points;
  7. int expense;
  8. int income;
  9. struct lnode *next;
  10. } ;
  11.  
  12. int main(void) {
  13.  
  14. lnode *head, *tail,*p;
  15.  
  16.  
  17. head=NULL;
  18. tail=NULL;
  19. p=NULL;
  20. FILE *infile = fopen("c:/H7.txt", "r");
  21.  
  22. if( infile == NULL ) return 1;
  23.  
  24. while(!feof(infile))
  25. {
  26. lnode *newptr=(lnode *)malloc(sizeof(lnode));
  27. newptr->next=NULL;
  28. if (head == NULL) {
  29. head = newptr;
  30. }
  31. else {
  32. tail->next=newptr;
  33. }
  34. tail = newptr;
  35.  
  36. fscanf(infile,"%s %d %d %d ", &tail->name,&tail->points,&tail->expense,&tail->income);
  37.  
  38.  
  39. };
  40.  
  41. p = head;
  42. while (p != NULL){
  43. printf("%s %d %d %d\n",p->name,p->points,p->expense,p->income);
  44.  
  45. p = p->next;
  46. };
  47.  
  48. //free memory
  49. p = head;
  50. while (p != NULL){
  51. free(p);
  52. p = p->next;
  53. };
  54.  
  55. head=NULL;
  56. tail=NULL;
  57. p=NULL;
  58.  
  59. system("pause");
  60. return 0;
  61. }
Runtime error #stdin #stdout 0.01s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty