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

How does if __name__ == '__main__': takes file path

I have written a driver code to take file path from user and use that file path in my functions. Driver code is as below; import sys if __name__ == '__main__': if len(sys.argv) != 2: print("Usage: %s input_file" % sys.argv[0]) …
svn_21
  • 17
  • 6
-3
votes
1 answer

IndexError: list index out of range - RPi + Stepper Motor

Trying to run the below on an RPi to get a stepper motor to work properly. Many are able to run the code with no issues, but I get the following error. [Argument 3] should be within aSequence, but not sure why it is not picking it up. Any advice on…
xDell
  • 1
-3
votes
2 answers

segmentation fault when using argv[1]

when i try to run this program with : ./prog_name eventCNT i confront with segmentation fault error while with other argument everything is ok... int main(int argc, char *argv[]) { printf("Application for up/down/random counter on 7 seg…
darkgray
  • 1
  • 2
-3
votes
3 answers

Is it possible to write a C program that functions differently according to argv[0]?

Is it possible to write a C program that functions differently according to argv[0]? In fact, I am working on an exercise from a C textbook. The exercise is to write a program that converts uppercase to lower or lowercase to upper, depending on the…
zell
  • 9,830
  • 10
  • 62
  • 115
-3
votes
2 answers

argc and argv in C

Suppose I have this example function int main(int argc, char** argv) { char* pChar = argv[2]; // Get the second argument "Word" char * pAdd = pChar + strlen(pChar); // 0 + 5 } and run by inputting ./fileName Hello World Since…
-3
votes
2 answers

I need my dictionary to be updated every time I amend it

I made a program which stores, updates, removes passwords for different accounts. However, although the program runs smoothly, whenever I restart the program, the PASSWORDS dictionary gets reset to the value in the program. Is there a way to update…
-3
votes
2 answers

Why command line argument -12345678969 is considered to be >1?

This is the program to check whether given number is Armstrong number or not #include #include #include int main(int argc, char *argv[]) { int num,n,sum=0; num=atoi(argv[1]); if(argc==2 && num>0 &&…
Aksh
  • 71
  • 1
  • 7
-3
votes
2 answers

argc, argv implementation c++

I have a problem with my main part of the program. I am trying to implement the arguments in main with argc, argv that will receive as input txt files. Also when I try to read the files I receive an error like : Variable i is used without being…
Maker10
  • 1
  • 2
-3
votes
2 answers

Read a file using argv

Currently the code is reading the file and sort the records, as shown below, #include"fileIO/file.h" #define MAX_RECORD_SIZE 256 // Bad style typedef struct{ int age; char *lastName; char *firstName; }Person; ..... int main(int argc,…
overexchange
  • 15,768
  • 30
  • 152
  • 347
-3
votes
2 answers

C programming and argv (pointer arithmetic)

So, I have been working on this simple block of code. I would like it to print, when I type in "./a.out -n" However, that is not working. I have been on stackoverflow trying to work on this, but no such luck. Any help would be appreciated. …
-3
votes
3 answers

learning Python the hard way argv and file

I am learning python from past weeks from sys import argv script,filename = argv print "We're delete the file %r" %filename print "If you want to stop ctrl+c (^c)" print "Please hit enter to continue" raw_input(">_") print "Opening file..." filen…
root
  • 43
  • 1
  • 6
-3
votes
2 answers

Mysterious Issue in Replicating Binary files in C

Hey community i'm having trouble in replicating binary files from the command line have a look at my try. The code under copies the first character on the srcFile and stops somehow, can you guys help me figure the way i can fix this and the reason…
-3
votes
1 answer

argv in C++ clearup

So I have this assignment(input a string and it will display the number of strings) where I have to explain why the argv[0] value and argv[3] values change. So when you step through the program (my string input is "run how now brown cow" argv[0]…
wade aston
  • 105
  • 3
  • 14
-3
votes
2 answers

How do i check argv[1] doesn't have any alphabetical characters?

This has been driving my entire C++ class nuts, none of us has been able to find a solid solution to this problem. We are passing information to our program through the Terminal, via argv* [1]. We would call our program ./main 3 and the program will…
lokilindo
  • 682
  • 5
  • 17
-3
votes
3 answers

How to index through argv[1] in C?

If I have: #include int main(int argc, char *argv[]) { int length = strlen(argv[1]); and argv[1] one is just a word, for example, "hello", how can I index through it backwards and print out letter by letter? I tried using strrev,…
Austin
  • 6,921
  • 12
  • 73
  • 138