NO

Author Topic: parameters  (Read 2986 times)

  • Guest
parameters
« on: April 15, 2008, 04:07:27 PM »
Hi...

I've got a problem concerning the Pelles C IDE and I hope you can help me:
I don't know how I can pass some parameters to
the main-function before I run the program as you can do it with MS-DOS.

Thanks in advance
« Last Edit: April 15, 2008, 04:09:56 PM by r§ »

Offline DMac

  • Member
  • *
  • Posts: 272
Re: parameters
« Reply #1 on: April 15, 2008, 04:48:02 PM »
Here is an example of how it is done:
Code: [Select]
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
    for(int i = 0; i < argc; i++)
{
if(0 == i) printf("The Application Path is: %s\n",argv[i]);
if(0 == strcmp("/1",argv[i])) printf("Arg /1\n");
else if(0 == strcmp("/2",argv[i])) printf("Arg /2\n");
else if(0 == strcmp("/S",argv[i])) printf("The String is: %s\n", argv[++i]);
else printf("No valid arguments\n");
}
scanf();
    return 0;
}

In the IDE you can enter command line arguments for debugging as follows:
Project>Project Options>General Tab>Command Line arguments:

I used the following to test this: /1 /S "Hello World" /2
No one cares how much you know,
until they know how much you care.

  • Guest
Re: parameters
« Reply #2 on: April 15, 2008, 06:17:13 PM »
Well, now it works, thanks a lot!
Greetings from Switzerland,