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

searching length of sting in arg[]

I'm trying to get string length from char argv array but I don't know how to check this. I'm writing 3 words to console for example: red blue yellow. Then I want to write out "yellow" but I don't know how to do that. I tried to save the words in a…
-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

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
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 is the ARGC value initialized if I don't enter it in the command prompt?

When I run the following code: void main(int argc, char** argv) { if (argc != 2){ fprintf(stderr, "Usage: %s video-dir-path\n", argv[0]); exit(-1); } XFishTracker ft(argv[1]); int id = 0; while (true) …
Isha
  • 3
  • 4
-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
2 answers

Output of following program

#include int main(int k) { if(k<10) printf("%d ",main(k+1)); return k; } output is: 10 9 8 7 6 5 4 3 2 In arguments of main() function, its argc but how is it used here?
Nikhil
  • 13
  • 1
  • 2
-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 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…
-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

Checking value of argc

I have problem with the number of argc that passed to program so, when i check the argc it's not equal to 2 !! need help, how can i solve that problem ? C code snippet : if (2 != argc) { fprintf(stderr, "Usage: %s \n", argv[0]); …
-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
1 2 3
16
17