Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take command line argument in Codeblock 10.05?

Tags:

c

environment

I am writing a C code in codeblock version 10.05.

The program is:

int main(int argc , char *argv[]) {     printf("Entered number is %s \n", argv[1]);     return 0; } 

However, when i compile current file, & then run the program, a terminal appears. But, the terminal doesn't wait for command line input & it directly outputs

<null> 

Note that in the above program, i have omitted the code for handling zero number of command line arguments. How can i supply command line arguments?

like image 927
Green goblin Avatar asked Aug 09 '12 17:08

Green goblin


People also ask

How do I grab command line arguments?

To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments. The value of argc should be non negative. argv(ARGument Vector) is array of character pointers listing all the arguments.

How do I enter command line arguments in CodeBlocks?

With code::blocks you can set your command line arguments like this in the menu: Project > Set programs' arguments... This opens a window where you can insert your parameters.

How do I run a command line argument in CMD?

Command line syntax Commands provide the action, or list of actions separated by semicolons, that should be implemented. If no command is specified, then the command is assumed to be new-tab by default. To display a help message listing the available command line arguments, enter: wt -h , wt --help , wt -? , or wt /? .

How command line arguments are used in program?

Command line arguments are passed to the main function as argc and argv. Command line arguments are used to control the program from the outside. argv[argc] is a Null pointer. The name of the program is stored in argv[0], the first command-line parameter in argv[1], and the last argument in argv[n].


1 Answers

With code::blocks you can set your command line arguments like this in the menu:

Project > Set programs' arguments...

This opens a window where you can insert your parameters.

like image 137
xQuare Avatar answered Oct 17 '22 20:10

xQuare