fork download
  1. /* Chapter 1. Basic cp file copy program. Win32 Implementation. */
  2. /* cpW file1 file2: Copy file1 to file2. */
  3.  
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #define BUF_SIZE 16384 /* Optimal in several experiments. Small values such as 256 give very bad performance */
  7.  
  8. int main (int argc, LPTSTR argv [])
  9. {
  10. HANDLE hIn, hOut;
  11. DWORD nIn, nOut;
  12. CHAR buffer [BUF_SIZE];
  13. if (argc != 3) {
  14. fprintf (stderr, "Usage: cp file1 file2\n");
  15. return 1;
  16. }
  17. hIn = CreateFile (argv[1], GENERIC_READ, FILE_SHARE_READ, NULL,
  18. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  19. if (hIn == INVALID_HANDLE_VALUE) {
  20. fprintf (stderr, "Cannot open input file. Error: %x\n", GetLastError ());
  21. return 2;
  22. }
  23.  
  24. hOut = CreateFile (argv[2], GENERIC_WRITE, 0, NULL,
  25. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  26. if (hOut == INVALID_HANDLE_VALUE) {
  27. fprintf (stderr, "Cannot open output file. Error: %x\n", GetLastError ());
  28. CloseHandle(hIn);
  29. return 3;
  30. }
  31. while (ReadFile (hIn, buffer, BUF_SIZE, &nIn, NULL) && nIn > 0) {
  32. WriteFile (hOut, buffer, nIn, &nOut, NULL);
  33. if (nIn != nOut) {
  34. fprintf (stderr, "Fatal write error: %x\n", GetLastError ());
  35. CloseHandle(hIn); CloseHandle(hOut);
  36. return 4;
  37. }
  38. }
  39. CloseHandle (hIn);
  40. CloseHandle (hOut);
  41. return 0;
  42. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:4:10: fatal error: windows.h: No such file or directory
 #include <windows.h>
          ^~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty