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
-3
votes
1 answer

Cygwin Strawberry perl @ARGV not read absolute path

I am working in Cygwin on a Windows 7 machine. I linked Cygwin perl to windows strawberry perl. 10:13 PM Thu Jan 14$ ls -ltr /usr/bin/perl lrwxrwxrwx 1 casper None 40 Nov 29 21:40 /usr/bin/perl -> /cygdrive/c/strawberry/perl/bin/perl.exe I have a…
capser
  • 2,442
  • 5
  • 42
  • 74
-3
votes
1 answer

How to use Printf like format string with argv

I'm trying to add support to my program for something that would allow me to enter /Input/Images/%03d.png /Output/Images/%03d.blah, but I'm not sure how to do that? I've googled around for every combination of format string, printf, and argv that I…
MarcusJ
  • 149
  • 4
  • 12
-3
votes
2 answers

Python argv and cmd

I'm trying to make a Python program that can correct exams automaticly, I have extra time and don't wanna wait for my teacher to correct them manually... Annyways when i use python argv like this: import sys def hello(a): print(a) a =…
duk
  • 704
  • 1
  • 6
  • 15
-3
votes
2 answers

How can I print out the file I just inputted into my program in C++/C

I'm trying to make my program output everything I typed into the command line but the file I streamed to it is not printing out because it doesn't get stored in argv. Here is how I execute: Input: ./program < file.txt Expected output: ./program <…
-3
votes
1 answer

c++ default argv if no parameter is parsed in console

i would like to give my file a default argv, if none is given in the console. It doesn't work cause of duplicate parameter names. if no parameter is given, i would like to use a fixed filename in the same folder. int main(int argc, char* argv[],…
Marabunta
  • 45
  • 1
  • 7
-3
votes
2 answers

If statement is not evaluating correctly

I am working on a console project and I just can't get this part to work. void execute(char* argv[]) { char* printex = "print"; if (argv[1] == printex) { print(argv); } else { cout << "Unknown function." << endl; …
Forrest4096
  • 159
  • 1
  • 8
-3
votes
1 answer

When I examine argv[1] and argv[2] I can't open and write to them

When I examine argv[1] and argv[2], I can't open and write to them! If I don't write the examine, part all things work. I have to use command line parameters as well. The main int main(int argc, char **argv[]) a part of while (i < MAXADAT &&…
user3724530
  • 53
  • 1
  • 5
-3
votes
2 answers

Trying to copy "0.75" as a double from argv[]

For some reason anything I try results in numbers after the decimal place being disregarded. sscanf(argv[5], "%.2lf", &add4); doesn't work add4 = atof(argv[5]); doesn't work Any help? 1: program name (aka for the program im trying to solve…
user3251142
  • 175
  • 7
  • 16
-3
votes
1 answer

Arguments in command line

Why do we need a mechanism like argv and argc in c programming language? How is this mechanism implemented? main(argc, argv) int argc; char *argv[]; { int i; for (i=1; i < argc; i++) printf("%s%c", argv[i], (i < argc-1) ? '…
-3
votes
4 answers

(C) How to use strncat() with **argv?

int main(int argc, char * argv[]){ char file_extension[10]; strncat(file_extension, argv[2][5], 6); When I do this, I get "warning: passing arg 2 of 'strncat' makes pointer from integer without a cast'. Does does anyone know how to fix…
user1472747
  • 529
  • 3
  • 10
  • 25
-3
votes
2 answers

Using Cin and Argv

How do I combine cin and argv in a script? int main(int argc, char* argv[]) c == argv[1]; cin >> c; How do you ignore cin if there's a command line argument, or do cin if there's no command line argument?
Seb
  • 1,966
  • 2
  • 17
  • 32
-4
votes
1 answer

Taking main argument

I have a problem with my code. I would like to know what the "variation" value is. But it always gives me extremely high or negative values. So when I type in terminal for example ./NAME 3 I end up with another number. How can i fix it? #include…
-4
votes
2 answers

Passing a file via command arguement into an array

So I'm trying to pass and command line argument into an array in my int main like this $< .\program nums.txt 8 but I'm getting errors and hit a dead-end with my knowledge on C++ code. (I'm relatively a new coder). Any help is greatly appreciated. …
-4
votes
1 answer

C: How to open a file using the parameter to main argv?

I've been trying to open a file using the char** argv parameter. But unfortunately, I stumped upon a problem reading the path to the file when I pass it in this format: program.exe Function SourceFile DestFile. I'm using notepad++ to write the code…
user123
  • 69
  • 9
-4
votes
3 answers

it is command line based c program to check for palindrome string and my answer is coming right but i had to supply arguments 2 times in the terminal

I think I made mistakes in the main function if there any please explain it to me as I am new to command line and functions #include < stdio.h > #include < string.h > int palindrome(char string[200]) { int i; int flag = 0; for (i = 0;…