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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.