Questions tagged [argv]

Argument vector containing the arguments passed in from the command line when starting a program. Used in the main method, in conjunction with argc.

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

Keep in mind that the first value in argv contains the program name.

Example usage:

int main(int argc, char **argv) {
    /* Some code involving command-line arguments from argv */
}

Notable Stack Overflow questions:

1247 questions
13
votes
2 answers

Save argv to vector or string

I need to save all arguments to a vector or something like this. I'm not a programmer, so I don't know how to do it, but here's what I've got so far. I just want to call a function system to pass all arguments after. #include "stdafx.h" #include…
user793035
  • 131
  • 1
  • 1
  • 3
13
votes
2 answers

Matching command line args

Starting out learning F#. Want to make a simple program that just tells me what it found in the command line args. I have: [] let main argv = printfn "%A" argv match argv with | [] -> 42 | _ -> 43 But this gives…
user1443098
  • 6,487
  • 5
  • 38
  • 67
13
votes
5 answers

Difference between (*++argv)[0] and while(c = *++argv[0])

I have the following snippet of code: int main(int argc, char *argv[]) { char line[MAXLINE]; long lineno = 0; int c, except = 0, number = 0, found = 0; while(--argc > 0 && (*++argv)[0] == '-') //These two lines …
Tool
  • 12,126
  • 15
  • 70
  • 120
12
votes
1 answer

Pass command line arguments as well as input from STDIN for Perl script?

I have a Perl script which takes both command line arguments and STDIN #!/usr/bin/perl -w use strict; use warnings; my $logpath = $ARGV[0]; print "logpath : $logpath\n"; print "Name : "; my $name = <>; chomp($name); print "my name is $name\n"; It…
naveenhegde
  • 177
  • 1
  • 1
  • 7
12
votes
4 answers

Problem with sys.argv[1] when unittest module is in a script

I have a script that does various things and access parameters using sys.argv but when the script gets to the unittest part of the code it says there is no module for this. The script that I have is: class MyScript(): def __init__(self): …
chrisg
  • 40,337
  • 38
  • 86
  • 107
12
votes
2 answers

Is argv[argc] equal to NULL Pointer

I read an article (forgot the URL), which said that argv[argc] is a NULL pointer (contains \0). To check whether if its true I wrote this code, yeah it exist. What I don't understand is, why does the OS include this NULL pointer at argv[argc]. Is it…
dimSutar
  • 1,425
  • 2
  • 13
  • 17
12
votes
4 answers

C argv what is the maximum size of data

Possible Duplicate: About command line arguments of main function How would I determine what the maximum size of data I could pass into a C main(int argc, char* argv)? Is there a macro somewhere in the standard that would define this? Is the…
Josh Petitt
  • 9,371
  • 12
  • 56
  • 104
11
votes
3 answers

executing a process with argc=0

Is it possible to execute a process whose argc = 0? I need to execute a program but it is extremely important for its argc to be equal to 0. Is there a way to do that? I tried to put 2^32 arguments in the command line so that it appears as if argc =…
Keeto
  • 4,074
  • 9
  • 35
  • 58
11
votes
2 answers

Node.js: process.argv vs. process.ARGV

I notice that Node defines both process.argv and process.ARGV (capitalized). The later isn't mentioned in the documentation and is, in every case I've encountered so far, the same object. Is ARGV just a historic holdover, or does it have a purpose?
Trevor Burnham
  • 76,828
  • 33
  • 160
  • 196
11
votes
3 answers

How to access argv[] from outside the main() function?

I happen to have several functions which access different arguments of the program through the argv[] array. Right now, those functions are nested inside the main() function because of a language extension the compiler provides to allow such…
Sergi
  • 113
  • 1
  • 4
11
votes
4 answers

Why check if (*argv == NULL)?

In the data structures class that I am currently taking, we have been tasked with writing a web crawler in C++. To give us a head start, the professor provided us with a program to get the source from a given URL and a simple HTML parser to strip…
Shaun Hamman
  • 2,287
  • 4
  • 21
  • 33
11
votes
1 answer

Python Popen sending to process on stdin, receiving on stdout

I pass an executable on the command-line to my python script. I do some calculations and then I'd like to send the result of these calculations on STDIN to the executable. When it has finished I would like to get the executable's result back from…
10
votes
4 answers

Char isn't converting to int

For some reason my C program is refusing to convert elements of argv into ints, and I can't figure out why. int main(int argc, char *argv[]) { fprintf(stdout, "%s\n", argv[1]); //Make conversions to int int bufferquesize = (int)argv[1]…
limasxgoesto0
  • 4,555
  • 8
  • 31
  • 38
10
votes
5 answers

How do I access argv / command line options in Dart?

And does Dart have a getopt library?
mcandre
  • 22,868
  • 20
  • 88
  • 147
10
votes
2 answers

Are the pointers to strings in argv modifiable?

Recently (Jan 2016, in case the question persists long enough) we had the question Are the strings in argv modifiable?. In the comment section to this answer, we (@2501 and I) argued whether it is really the strings of characters (an example…
cadaniluk
  • 15,027
  • 2
  • 39
  • 67
1 2
3
83 84