Ok, now I can what you are doing.
A few comments:
1. You can name the parameters in the main() function anything you want, but traditionally the int parameter is named 'argc' (argument count) and the char pointer array is named 'argv' (argument variables or vector). There's also a third parameter (that most programmers rarely use) called 'envp', which is also a char pointer array, and contains environment variables.
2. On line 23 of your code, you are comparing an unsigned int with an int (argv).
3. Your program does not support quoted input (e.g. "Hello World") in cases where the white-space must be stripped away.
Code:
$ ./lcase "Hello World" # This one is ok
hello world
$ ./lcase -l "Hello World" # This one does not work
hello world
As for receiving data via pipes, there are bash shell types that I indicated earlier. One involves using the vertical bar, which is typically referred to as the pipe symbol (that is |), and the other is the standard-in redirection symbol, or the less-than character <.
The only way to receive data using these types of constructs is to read from standard-in. Your program will need to determine whether it is going to process exclusively the command-line arguments (via argc and argv), or read from standard-in. If the latter, there may be one argument passed to you via argc/argv, and that is the -l option.
Note, after you have augmented your program to support reading from standard-in, you should be able to test it like this:
Code:
$ ./lcase
Hello World <--- Your input
hello world <--- app output
<ctrl-d>
$ ./lcase -l
Hello World <--- Your input
helloworld <--- app output
<ctrl-d>
P.S. In lieu of the vector, consider combining argc/argv input into a space-delimited string. For example:
Code:
std::string input;
int start;
//TODO: Determine if start should be set to 1 or 2, depending whether the -l option is provided. Or consider using getopt().
// Combine all cmd-line input into one large string.
for (int i = start; i < argc; ++i)
{
input += argv[i];
input += " ";
}
Bookmarks