fork download
  1. #include<stdio.h>
  2. int main()
  3. {
  4. FILE *fp;
  5. char ch, file[100];
  6. printf("opening the file\n");
  7. fp = fopen("sample1.txt", "w");
  8. if(fp != NULL)
  9. {
  10. printf("contents of file is\n");
  11. ch = fgetc(fp);
  12. while ( ch != EOF)
  13. {
  14. putchar(ch);
  15. ch= fgetc(fp);
  16. }
  17. fclose(fp);
  18. }
  19. else
  20. printf("\nError while opening file...");
  21. }
  22.  
Success #stdin #stdout 0.01s 5472KB
stdin
hello
stdout
opening the file

Error while opening file...