I have written a basic shell program that handles 3 commands: cat, cp, and cryptix for encrypting files. 'cat' and 'cp' act exactly as they do in any normal linux shell. 'cat' can take any number of paths to files as arguments. 'cp' takes 2 arguments (source, destination). And 'cryptix' takes 3 arguments (integer key, source, destination). I use 2 functions outside of main to help parse out the commands and arguments given on the command line. The first is getCommand() which returns an integer that represents one of the commands to determine which command was given. The second is getArgument() which returns a char * that is the argument that is next in line to be read from the command line. If an argument is a path is to a file that doesn't exist, then the program writes an appropriate message to stdout that the file couldn't be found. My only problem comes when a file doesn't exist at the given path. If I give the command "cat file1 file2" and one or both files don't exist, then I end up receiving a segfault error and the program crashes. I am able to read in the argument "file1" but since it can't be found the program crashes, instead of writing a message to stdout that the file doesn't exist. When reading the arguments from the command line I check to see if the argument that was extracted is NULL and if not then I begin to process the command on that argument. If it is NULL then I attempt to write that error message. I guess I'm not checking for valid arguments in the correct way but I really don't know how to go about fixing this because it has stumped me for a few days now.
I have been working remotely on linux through an SSH client, but I can't connect to any linux machines right now. I will post the code that is in question when I am able to get to it. But for now, if anyone has any suggestions as to how to go about correctly identifying when an invalid argument is given, please share your thoughts.