Yes, I had done that. Which is why I said the program worked fine in the first place, I was just curious as to why I couldn't pass the arguement the way I was trying to in the example. Anyway, thanks to Prelude's advice, I've elimated the use of String.h completely to simplify the program.
Here is the finished product, it works fine:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]) {
if (argc == 2) {
cout << argv[1] << " has " << strlen (argv[1]) << " letters in it.";
}
else if (argc == 3 && strcmp ( argv[1], "file" ) == 0) {
ifstream input_file(argv[2]);
if(!input_file) {
cout << argv[2] << " does not exist";
return 0;
}
char x;
int letter = 0;
while(input_file.get(x)) {
if (x != '\n' && x != ' ')
letter++;
}
cout << argv[2] << " has " << letter << " letters in it.";
}
else {
cout << "Proper format is 'count <string>' or " << endl
<< "'count file <file>'";
return 0;
}
return 0;
}
You can compile it if you wish to try it, though it's probably below those that have replied to this, thus far.