fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "string.h"
  4. #define MAXLEN 5
  5. struct str *talloc(void);
  6. struct str *GetList(struct str *q,char *word);
  7. struct str{
  8. char word[6];
  9. struct str *next;
  10. };
  11. int main()
  12. {
  13. struct str *list;
  14. list=NULL;
  15.  
  16. char word[6];
  17. FILE *file;
  18. file=fopen("Test.txt","r");
  19. while (fgets(word,5,file)){
  20. printf("%s",word);
  21. list=GetList(list,word);
  22.  
  23. }
  24. printf("\n");
  25. prin(list);
  26. return 0;
  27. }
  28.  
  29. struct str *GetList(struct str *q, char *word){
  30. if (q==NULL){
  31. q = talloc();
  32. q->next=NULL;
  33. strcpy(q->word,word);
  34. return q;
  35. }
  36. q->next=GetList(q->next,word);
  37. return q;
  38. }
  39.  
  40. struct str *talloc(void){
  41. return (struct str *)malloc(sizeof(struct str));
  42. }
  43.  
  44. void prin(struct str *q){
  45. printf("%s",q->word);
  46. if(q->next!=NULL);
  47. prin(q->next);
  48. }
Runtime error #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Standard output is empty