So I haven't programmed in a long time now and I'm working through a Windows System Programming book and for some reason I can't figure out why this simple file copy program keeps giving me Error 2 (Can't find file) when the file is clearly right there. I tried searching but couldn't find someone with the same issue.
Below is the code and a screenshot of the Command Prompt.
#define BUF_SIZE 256
int main(int argc, LPTSTR argv)
HANDLE hIn, hOut;
DWORD nIn, nOut;
if(argc != 3)
printf("Usage: WinFileCopy file1 file2\n");
printf("Filename: %s\n", argv);
hIn = CreateFile(argv, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(hIn == INVALID_HANDLE_VALUE)
printf("Cannot open input file. Error: %x\n", GetLastError());
hOut = CreateFile(argv, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hOut == INVALID_HANDLE_VALUE)
printf("Cannot open output file. Error: %x\n", GetLastError());
while(ReadFile(hIn, buffer, BUF_SIZE, &nIn, NULL) && nIn > 0)
WriteFile(hOut, buffer, nIn, &nOut, NULL);
if(nIn != nOut)
printf("Fatal write error: %x\n", GetLastError());
Also, I tried the relative path (in above screen shot), absolute path, running as admin, etc.