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
-4
votes
3 answers

meaning of this code :for(i=0;argv[1][i]!='\0';i++)

I found this code from book named "Learn C the hard way", but I am could not understand the meaning and purpose of : for(i=0;argv[1][i]!='\0';i++){ char letter=argv[1][i];
Pratik Parmar
  • 321
  • 3
  • 12
-4
votes
1 answer

Error parsing argv as char*

I want to read argv[1] as char* so this is what I do using namespace std; const char *myarg = NULL; void Plots(char* file); int main( int size_t argc, char* argv[] ) { myarg = argv[1]; cout<<" this is a test…
Just_Newbie
  • 447
  • 1
  • 4
  • 11
-4
votes
1 answer

C index in string inside array

How can I access char from strings inside array of strings in index 1, but with pointer way I mean this way *(abc + i) for e.g: int main(int argc, char** argv)// argc =2, argv = file name and "abcd" { printf("%c",____)//<--- here i want b from…
ariel20
  • 15
  • 10
-4
votes
1 answer

Main crashes before returning 0

I'm writing a program in C++ and have encountered the most bizarre error. My program crashes right before main is to return 0. I do not understand how the program can crash after finishing and yet before returning zero. How is this possible? The…
bigcodeszzer
  • 916
  • 1
  • 8
  • 27
-4
votes
1 answer

About `argv` and opening a file with command line

I have this code: #include int main ( int argc, char *argv[] ) { FILE *file; int x; if ( argc != 2 ) printf( "Use: %s file name", argv[0] ); else { if ((file=fopen( argv[1], "r" ))== 0 ) …
Beth
  • 1
  • 2
-4
votes
1 answer

how to run c++ proram with int main(int argc, char *argv[])

readme.txt file: To use the program you should compile the file "main.cpp" and subsequently run the executable passing as the first argument the port number to which the application will listen for incoming data points (the incomplete data set…
-4
votes
1 answer

Command line arguments, sys.argv

I am reading Learn Python the Hard Way (3rd Ed.) and there is an exercise I was trying, but I am just unable to get it; the arguments and parameters stuff (Exercise 13). I've read other answers on the site for the same question, but my doubts…
sunp
  • 21
  • 6
-4
votes
1 answer

Why is my value of argv[1] changing? (C)

my program takes two command line inputs, stock.csv and coins.csv. Near the start of my program I have load_check = load_data(&tm, argv[1], argv[2]); which initializes the files into linked lists. Problem is, somehow this line of code is changing…
An0nx
  • 19
  • 2
  • 9
-5
votes
1 answer

C++ int main(int argc, char* argv[])

how do i save int argc, char* argv in to int someting. i am trying to get the arguments from a test program and save it into int ****; #include #include using namespace std; int main(int argc, char* argv[]) { int limit =…
Poo Po
  • 11
  • 3
-5
votes
1 answer

Open files with argv gives me file NULL

I have a program that should take the file's name from command line using argc and argv. Printing argv[1] and argv[2] show me the exactly names I passed, but passing argv[1] and argv[2] as parameters to open the files in another function just show…
Ing
  • 1
  • 2
-5
votes
1 answer

Using int main(int argc, char **argv) in c++

I'm encountering a problem trying to use char** argv from the main. My goal is to use argv[2] to pass to a string in another class called Game. Does someone have an idea how I can use argv and pass it as a string to another class? int main(int argc,…
Erry07
  • 29
  • 1
  • 2
  • 5
-5
votes
1 answer

I Don't Know What is argv and what's different with raw_input()?

I Learn Python From "Learn Python the Hard way" I don't know what is argv !! (please explain argv with Example and text) Question 2: What is Different between raw_input & argv ?
Shayan
  • 1
  • 4
-6
votes
2 answers

second argument of the command line arguments in a format other than char** argv or char* argv[]

To solve my problem here, I want to know if/how I can define the second variable of the command line arguments in a format other than char** argv or char* argv[]. The reason is that pybind11 doesn't allow either of those in the inputs of a function.…
Foad S. Farimani
  • 12,396
  • 15
  • 78
  • 193
-6
votes
1 answer

What is the output of this C code (run without any command line arguments)?

What is the output of this C code (run without any command line arguments)? #include int main(int argc, char *argv[]) { while (*argv != NULL) printf("%s\n", *(argv++)); return 0; } In this program argv gives the base…
Ananya
  • 35
  • 1
  • 6
-6
votes
2 answers

C argv[2]++ vs (char*)argv[2]++?

Why are argvs act odd? Example: This will work as expected, print the 1st character of the 1st argument. printf("%c", *argv[1]); This however will print the character that's in the ascii table (aka "one bigger" represented as a number) instead of…
Mark Rowra
  • 49
  • 1
  • 1
1 2 3
83
84