LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   command line argument in c (https://www.linuxquestions.org/questions/linux-newbie-8/command-line-argument-in-c-725293/)

vipin_jss 05-11-2009 05:55 PM

command line argument in c
 
hii to all

i have a problem related to command line argument in c

#include <stdio.h>

main( int argc, char *argv[] )
{
if( argc == 2 )
printf("The argument supplied is %s\n", argv[1]);
else if( argc > 2 )
printf("Too many arguments supplied.\n");
else
printf("One argument expected.\n");
}



i have this code but i dont know how to execute this code in gcc plz be descriptive thanks

Tinkster 05-11-2009 05:59 PM

You don't execute it in gcc, you compile it.

man gcc
holds a host of information to explain how. Have a read, highly
recommendable ;}



Cheers,
Tink

bencharluo 05-11-2009 06:20 PM

first: gcc -o yourtext yourtext.c
second: ./yourtest parameter1 parameter2...
last: you will get the answer you want

vipin_jss 05-11-2009 06:23 PM

i executed this code as
gcc code.c

next for the output i type code 3 it says command not found

when i try ./a.out 34

it is working my problem is why code 3 is not working

Tinkster 05-11-2009 06:25 PM

man gcc
/-o



Cheers,
Tink

vipin_jss 05-11-2009 06:28 PM

okie thanks i got the point

Tinkster 05-11-2009 06:47 PM

Quote:

Originally Posted by vipin_jss (Post 3537596)
okie thanks i got the point

Good =}

Quote:

Originally Posted by man gcc
Code:

      -o file
          Place output in file file.  This applies regardless to whatever sort of output is being produced, whether it be an executable
          file, an object file, an assembler file or preprocessed C code.

          If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its
          assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.




Cheers,
Tink


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