fork(8) download
  1. #include stdio.h
  2. #include stdlib.h
  3.  
  4. int main(void)
  5. {
  6. FILE *outputFile;
  7. char file_name[256];
  8. int ch;
  9.  
  10. printf("This program saves your console input to an output file.\n");
  11. printf("Enter the name of the output file: ");
  12. scanf("%s", file_name);
  13. flush_input_buffer();
  14.  
  15. if (outputFile = fopen(file_name, "w") == NULL) {
  16. printf("Cannot open %s for writing.\n", file_name);
  17. return EXIT_FAILURE;
  18. }
  19.  
  20. printf("Enter your input (Press Ctrl-D when done) ...\n");
  21.  
  22. while ((ch = getc(stdin)) != EOF) ; {
  23. putc(ch, outputFile);
  24. }
  25.  
  26. fclose(outputFile);
  27.  
  28. printf("===== Ctrl-D pressed ===== \n");
  29. printf("Input saved to file %s\n", outputFile);
  30.  
  31. return EXIT_SUCCESS;
  32. }
  33.  
  34. void flush_input_buffer() {
  35. while (getchar() != '\n') {
  36. continue;
  37. }
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:10: error: #include expects "FILENAME" or <FILENAME>
 #include stdio.h
          ^
prog.cpp:2:10: error: #include expects "FILENAME" or <FILENAME>
 #include stdlib.h
          ^
prog.cpp: In function ‘int main()’:
prog.cpp:6:1: error: ‘FILE’ was not declared in this scope
 FILE *outputFile;
 ^
prog.cpp:6:7: error: ‘outputFile’ was not declared in this scope
 FILE *outputFile;
       ^
prog.cpp:10:68: error: ‘printf’ was not declared in this scope
 printf("This program saves your console input to an output file.\n");
                                                                    ^
prog.cpp:12:22: error: ‘scanf’ was not declared in this scope
 scanf("%s", file_name);
                      ^
prog.cpp:13:20: error: ‘flush_input_buffer’ was not declared in this scope
 flush_input_buffer();
                    ^
prog.cpp:15:38: error: ‘fopen’ was not declared in this scope
 if (outputFile = fopen(file_name, "w") == NULL) {
                                      ^
prog.cpp:15:43: error: ‘NULL’ was not declared in this scope
 if (outputFile = fopen(file_name, "w") == NULL) {
                                           ^
prog.cpp:17:8: error: ‘EXIT_FAILURE’ was not declared in this scope
 return EXIT_FAILURE;
        ^
prog.cpp:22:19: error: ‘stdin’ was not declared in this scope
 while ((ch = getc(stdin)) != EOF) ; {
                   ^
prog.cpp:22:24: error: ‘getc’ was not declared in this scope
 while ((ch = getc(stdin)) != EOF) ; {
                        ^
prog.cpp:22:30: error: ‘EOF’ was not declared in this scope
 while ((ch = getc(stdin)) != EOF) ; {
                              ^
prog.cpp:23:20: error: ‘putc’ was not declared in this scope
 putc(ch, outputFile);
                    ^
prog.cpp:26:18: error: ‘fclose’ was not declared in this scope
 fclose(outputFile);
                  ^
prog.cpp:31:8: error: ‘EXIT_SUCCESS’ was not declared in this scope
 return EXIT_SUCCESS;
        ^
prog.cpp: In function ‘void flush_input_buffer()’:
prog.cpp:35:16: error: ‘getchar’ was not declared in this scope
 while (getchar() != '\n') {
                ^
stdout
Standard output is empty