in your block int main(int argc, char** argv) { .
if (argc == 3) { // then there were 3 arguments, the program name, and two parameters } else if (argc == 2) { // then prompt for the "second" argument, as the program name and one // parameter exists } else { // just print out the usage, as we have a non-handled number of arguments }
now if you want to check if a file exists that is different from checking for the presence of a program argument. Basically try to open the file and read it, but pay close attention to looking for whole error codes and checking for errors. This will prevent your program from switching to a bit where these critical operations are supposed to work.
There is a common, but erroneous concept among new programmers when working with files in C. In principle, you really need to make sure that a certain block of code is working (copy block in your case), so they check, check, and double check conditions before executing the block. Check if the file exists, check if it has the correct permissions, check that it is not a directory, etc. My recommendation is that you do not do this.
Your copy unit should be able to fail properly, just as it should be successful. If this fails, then usually you have all the information you need to print a meaningful error message. If you check first and then act, there will always be a short period of time between verification and action, and this period of time will eventually see that the file is deleted or modified after the checks have passed, but before it is read. In this scenario, the entire pre-validation code did not provide any benefit.
Code without benefits is just a breeding ground for future bugs and architectural problems. Do not waste time writing code that has dubious (or not) benefits. When you suspect that some of the code you wrote is of little use, you need to rebuild your code to put it in the right place. When you suspect that code written by someone else is not very profitable, you first need to doubt your suspicions. It is trivially easy not to see the motives underlying the code fragment, and even more so when you are just starting a new language.
Good luck
--- code for the tired ---
#include <errorno.h>