Okay, I was trying to write a program that will take in command line inputs of character or strings, separated by spaces. Ignore spaces, however i am going to want to be able to separate a and b from each other, or c and d from each other. So when I output *arg[1], i just get whatever the argv begins with, I'm stumped on how to output something like character b from the command line input pointed by argv.

If theres an easier way to do this, i can do that also, but I decided to use this one. I tried searching around and couldn't find exactly what I was looking for. Later, I want to add the characters to a stack. Please take a look.

Command line: DRIVER ab cd
outputs: a
int main(int argc, char *argv[])

char temp[5];
temp = *argv[1];
cout << temp << " " << "\n";

This should help you understand what is going on (compile, run and play with this):

int main(int argc, char *argv[]) {

  cout << "the 0th argument is: " << argv[0] << endl;
  cout << "it first two chars are: " << argv[0][0] << " " << argv[0][1] << endl;

  cout << "all the other arguments were:" << endl;
  for(int i = 1; i < argc; ++i) 
    cout << argv[i] << endl;
  return 0;

argc is the number of arguments in the command-line (which includes the application's name).

argv is an array of C-strings (char*), the size of the array is argc. Each element in the array "argv" is a C-string. The zeroth being the name of the application itself, and the rest being each command-line argument (separated by spaces) (note that arguments between quotes "" will be put into one such C-string).

Yes, that makes much for sense. At first I was trying something similiar to this, but it was a type-mismatch.

I was trying to use: temp = *argv[0][0];
but it must be temp = argv[0][0];

Thankyou for this, a great help!

This question has already been answered. Start a new discussion instead.