fork download
  1.  
  2.  
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. struct Node
  6. {
  7. char data;
  8. struct Node * next;
  9. };
  10. struct Node * head1;
  11.  
  12.  
  13. struct Node * insert(char ch,struct Node * head)
  14. {
  15. struct Node * temp=(struct Node *) malloc(sizeof(struct Node));
  16. temp->data=ch;
  17. temp->next=head;
  18. head=temp;
  19. }
  20. void print(struct Node * head)
  21. {
  22.  
  23. while(head!=NULL)
  24. {
  25. printf("%c\n",head->data);
  26. head=head->next;
  27. }
  28. }
  29. int main(int argc,char *argv[])
  30. {
  31. FILE *file1;
  32. file1=fopen(argv[1],"r");
  33. if(file1==NULL)
  34. {
  35. printf("File not found or unable to read\n");
  36. return 0;
  37. }
  38. head1=NULL;
  39.  
  40. char ch=getc(file1);
  41. while(ch!=EOF)
  42. {
  43. printf("%c\n",ch);
  44. head1=insert(ch,head1);
  45. ch=getc(file1);
  46. }
  47. print(head1);
  48.  
  49.  
  50. fclose(file1);
  51.  
  52. return 0;
  53. }
Success #stdin #stdout 0s 2140KB
stdin
Standard input is empty
stdout
File not found or unable to read