Reputation: 135
I'm new to code blocks and I'm writing code that takes in a command line input such as a file name, but once I compile and run the Code the console prompts "press any key to continue" like always and I'm unable to type anything in the console? So I can I write in console making my code run.
Upvotes: 0
Views: 1725
Reputation: 61337
You cannot pass commandline arguments to your program in the Code::Blocks console, because Code::Blocks has already started your program when you see the console. You need to specify any commandline arguments in the the Project settings before you run it. Then, when the console appears, your program will be running with the commandline arguments you have specified.
To specify commandline arguments, select the Project menu on the top menu-bar of the IDE. In the Project menu, select Set program's arguments, enter the commandline arguments you want and then OK out.
Once your program is running in the console (with or without commandline arguments), if it requests any input from the user, then you will be able to type the required input in the console.
Upvotes: 1
Reputation: 9599
CodeBlocks will run your executable file without arguments, so you'll probably want to do it yourself. Open a command prompt (cmd.exe
) and invoke your program with the desired arguments: C:/path/to/your/project/bin/Debug/program.exe filename
.
Alternately you can request the user input via scanf
or similar.
Hope it helps!
Upvotes: 2