0

I'm trying to pass arguments to my program so that I can store them into an array. For some reason my IDE/compiler is treating the blank space in between arguments as an argument. I'm using bloodshed, but it doesn't say anything about a seperation character. Can anyone tell me what I'm doing wrong?

I'm doing something like this:
Bob Bill
that should be two parameters, but for some reason it returns three.

3
Contributors
2
Replies
4
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

It appears to work for me. The version of my Dev-C++ IDE is 4.9.9.2. One should note that the first parameter is always the name of your program.

This is the program I used for testing.

#include <stdio.h>

int main(int argc, char *argv[])
{
  if ( argc >= 3 )
  {
    printf( "arg[1] = %s\n", argv[1] );
    printf( "arg[2] = %s", argv[2] );
  }
  
  getchar();
  return 0;
}

This picture shows how I passed the parameters.

[IMG]http://img438.imageshack.us/img438/724/parameters1fz.th.jpg[/IMG]

And this is my output.

arg[1] = Bob
arg[2] = Bill
0

I'm trying to pass arguments to my program so that I can store them into an array. For some reason my IDE/compiler is treating the blank space in between arguments as an argument.

There is nothing wrong with your compiler or IDE -- that is the customary way C program startup code uses to parse and build argv strings. If you have a parameter that y0u want to include spaces, then you have to surround it with double quotes

c:> myprogram "This is one parameter" <Enter>

in the above, argc will be 2, argv[0] == the name of the program and argv[1] == "This is one parameter". Without the quotes, argc == 5 and there will be 6 strings in argv.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.