Questions tagged [argc]

The number of arguments given to the program, found as a parameter to main in some languages, notably C.

argc stands for argument count, and represents the number of arguments given to the program, or main, in a command-line. It is used in conjunction with .

Keep in mind that argc also counts the program name.

Notable Stack Overflow questions:

243 questions
5
votes
3 answers

Can I use the address of argc in main as random source?

I want to create a program which only needs one random number, so I try to use the address of argc in main function as random source because I think the location of the program in memory is random, and also it can save some include statements, so I…
ggrr
  • 7,737
  • 5
  • 31
  • 53
5
votes
2 answers

Are there any other arguments that main() can accept?

I recently came across the following in my searches regarding environment variables in C: int main (int argc, char *argv[], *char *envp[]) I have searched around and can't find anything conclusive regarding my question. What are all of the…
Deanie
  • 2,316
  • 2
  • 19
  • 35
4
votes
2 answers

Jython 2.5.1: Calling From Java into __main__ - how to pass in command line args?

I'm using Jython from within Java; so I have a Java setup similar to below: String scriptname="com/blah/myscript.py" PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState()); InputStream is =…
monojohnny
  • 5,894
  • 16
  • 59
  • 83
4
votes
1 answer

Is my understanding of how this C program works correct?

in the following program: #include #include int main(int argc, char *argv[]) { char *delivery = ""; int thick = 0; int count = 0; char ch; for (int i = 0; i < argc; i++) { …
computronium
  • 445
  • 2
  • 11
4
votes
3 answers

Is there any way to set argv and argc parameters in runtime?

I need to debug my program, the problem is that this program takes couple of parameters. How Can I debug program which takes a parameters ?? Can I somehow modify argc and argv parameters in runtime ??
reminder
  • 41
  • 1
  • 1
  • 2
4
votes
3 answers

Tcl $argc and $argv variables

I'm kinda new to tcl but I have to write a proc that looks like this: proc TestVerb { Data Data_txt } { VERBATIM [format "// Data: $Data - $Data_txt"] if { $argc == 2} { VERBATIM {// SUCCESS //} else { exit 1 } I call the proc like this:…
Flaxter
  • 53
  • 1
  • 1
  • 3
4
votes
2 answers

How to get command line arguments from VimL?

How can I access the arguments that were given to Vim on the command line under Windows? I'm looking for the the equivalent to argv[] in C. Under linux you can read /proc/self/cmdline. Example: vim -c ":echo split( readfile( \"/proc/self/cmdline\",…
4
votes
2 answers

Change a command line argument argv

I would like to modify or erase a command-line argument in argv. //Somewhere near the top of main() bool itemFound(false); for(int i=1; i
Madeleine P. Vincent
  • 3,361
  • 5
  • 25
  • 30
4
votes
5 answers

How to check if an argument was given or not?

//Checks if an argument was specified if (argv[1] != "") strcpy(Buff1, argv[1]); else strcpy(Buff1, "default"); If I run: ./program test Buff1 = test If I run: ./program Buff1 = PACKAGES/=packages How do I make it if nothing was…
user2369405
  • 217
  • 1
  • 4
  • 10
3
votes
5 answers

how to tell when you've reached the end of a C array? (specifically argv)

been asked a question on this, basically coming up with argc...without actually having argc if your given argv, which as I understand essentially a array of pointers to the relevant char arrays of each inputted argument, how would I actually go…
SGE
  • 2,317
  • 3
  • 19
  • 16
3
votes
2 answers

getopt() in C not working correctly after if statement

I would like to implement a copy of the Linux head commmand. If the user types in ./cprogram head -(option here) I would like for the option to appear but for some reason my code never enters the options switch statement. For example the command…
mohelt
  • 55
  • 2
  • 6
3
votes
2 answers

replacing the command line arguments int argc and char** argv with std::vector

Following this post, where I have found a temporary workaround for my other problem, I want to know if I can replace the int argc, char** argv with a std::vector variable/object. Consider the imaginary code: #include #include…
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
3
votes
4 answers

QApplication app(argc, argv)

I noticed that the main.cpp in a Qt application has to contain the following line: QApplication app(argc, argv); I know that argc is the number of command-line arguments, and argv is that array list of command-line arguments. But, the question in…
Simplicity
  • 47,404
  • 98
  • 256
  • 385
3
votes
3 answers

Segmentation fault with no parameters on main( )

I have this simple bubblesort program that when compiled on macOs works correctly, but when compiled on linux (with gcc), gives a segmentation fault at runtime. I would love to understand why. #include #include "alg_utils.h" void…
ovalb
  • 555
  • 6
  • 15
3
votes
1 answer

Why aren't there any passed arguments to argv[]?

So, I noticed that my argc is always 1 as I will always get the message Error: missing command line arguments!, but as stated in code I am using argv[1] and argv[2] to read the files names. Shouldn't automatically argc be 3 in this case, and to be…
ISimion
  • 108
  • 8
1
2
3
16 17