LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Howto execute a command in C if argv[1] is equal to -A (https://www.linuxquestions.org/questions/programming-9/howto-execute-a-command-in-c-if-argv%5B1%5D-is-equal-to-a-529303/)

daYz 02-15-2007 10:07 AM

Howto execute a command in C if argv[1] is equal to -A
 
Hi,

I want to execute a command when the first argument of a C program I am writing, is equal to -A.

Can someone show me how that can be done? I am starting with C and I am unable to achieve this myself.

Thanks

Ben

Guttorm 02-15-2007 10:35 AM

maybe like this?

Code:

int main(int argc, const char *argv[])
{
  if (strcmp(argv[1],"-A") == 0)
    system("command...");
}


daYz 02-15-2007 10:49 AM

Quote:

Originally Posted by Guttorm
maybe like this?

Code:

int main(int argc, const char *argv[])
{
  if (strcmp(argv[1],"-A") == 0)
    system("command...");
}


Thanks!! It works indeed.

Regards,

Ben

wee-face 02-15-2007 10:09 PM

Another function you might want to look into is popen(), if you're
familiar with file I/O it will be a breeze.

daYz 02-16-2007 03:06 AM

Quote:

Originally Posted by wee-face
Another function you might want to look into is popen(), if you're
familiar with file I/O it will be a breeze.

Thanks wee-face. I will take a look at it.


All times are GMT -5. The time now is 02:02 PM.