fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <errno.h>
  4. #include <stdarg.h>
  5.  
  6. void errmsg_exit(const char *fmt, ... ) {
  7. va_list args;
  8. va_start(args, fmt);
  9. vfprintf(stderr,fmt,args);
  10. fprintf(stderr,"\n");
  11. va_end(args);
  12. exit(EXIT_FAILURE);
  13. }
  14.  
  15. int main(int argc,char *argv[]) {
  16. if(argc != 3)
  17. errmsg_exit("%s","./program file_to_read.txt file_to_write.txt");
  18.  
  19. FILE *read = fopen(argv[1],"r");
  20. FILE *write = fopen(argv[2],"w");
  21.  
  22. if(!read || !write)
  23. errmsg_exit("%s : %s or %s\n",strerror(errno),argv[1],argv[2]);
  24.  
  25. int c;
  26. while((c = fgetc(read)) != EOF)
  27. fputc(c,write);
  28.  
  29. fclose(read);
  30. fclose(write);
  31.  
  32. return 0;
  33. }
Runtime error #stdin #stdout #stderr 0s 2244KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
./program file_to_read.txt file_to_write.txt