argv[1] should be inputfile in your example. check it out by running the program with the command line arguments you have listed. comment out the call to readfile() and put a cout << argv[1] << endl; in the program to prove it. Put in a cout << fname << endl; after you assign argv[1] to fname to be sure you have the same information int fname.