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

argc giving erroneous value in C program

I want to enter some command line arguments at run time. Like ./program abc def ghi argc would be 4 in this case. No problem in this. But if I do ./program abc def * or even ./program * abc def the variable argc gives me a value far larger than…
tf3
  • 447
  • 1
  • 4
  • 16
3
votes
4 answers

Significance of argc and argv in int main( int argc, char** argv ) in OpenCV

In the following program for loading and displaying image in openCV #include #include #include using namespace cv; using namespace std; int main( int argc, char** argv ) { …
venus
  • 87
  • 1
  • 3
  • 10
3
votes
2 answers

C++: cin >> *char

So, I'm currently writing a line editor as a learning project on I/O, writing files, and the like. It is written in C++, and I am currently trying to write out to a file of the user's choosing. I have CLI arguments implemented, but I currently have…
ubsan
  • 70
  • 1
  • 6
3
votes
0 answers

Arguments in main() ignored when debugging in Visual C++

Up to this point I've been able to correctly view the output of my C codes by using the debugging command in Visual C++. However, when the script relies on parameters in the main function (eg/ argc, argv), the debugger seems to ignore both…
ericgrosse
  • 1,490
  • 20
  • 37
2
votes
5 answers

argc/argv random data/behavior

Here is my minimal reproducible example: #include int main( int argc, char* argv[]) { printf (" this is the contents of argc:%d\n",argc); int i; for (i = 0; i < argc ; i++){ printf(" argv = %d =…
2
votes
2 answers

Why do programs with arguments passed in argc and argv get different results when executed in different ways

void main(int argc,char *argv[]) { for (int i = 0; i < argc; i++) { printf("%s ", argv[i]); } } when I use command ./test 1 2 3 in terminal to execute this program, I got result ./test 1 2 3 ,but when I use function…
Mr Right
  • 35
  • 4
2
votes
4 answers

Can I use std::string* argv as main function argument?

Usually I see: int main(int argc, char** argv) But can I use: int main(int argc, std::string* argv) instead? If it's not possible how can I convert char* to std::string? PS: I am using C++11.
Raea6789
  • 141
  • 1
  • 11
2
votes
2 answers

Asterisk in C++ console lists all files in folder, why?

So I wanted to create a simple console calculator that'd take arguments via the int main(int argc, char ** argv) function. It works for regular examples, but trying multiplication with '*' started giving me way too many arguments listed in argv[],…
2
votes
2 answers

Why is Xcode not recognizing argc?

I want to check if the caller has passed a value for outOfand if not then I want to use a default value. I did some research online and saw that you can use argc to see how many variables are passed. I tried using that in the below code but I got…
2
votes
1 answer

Starting program using execv and passing arguments with out raising argc

Ive been given this code in class: int main(int argc, char **argv) { if(argc) { return 1; } puts(argv[3]); return 0; } Now, Im supposed to write a second program which executes this…
LucaW
  • 79
  • 1
  • 6
2
votes
2 answers

strlen(*argv) produces an unusual result

I ran the following just for fun, but cannot account for the result. Assume ./test WTF? was run at the command line, and the output produced was WTF? 6 2. Why is there such a vast discrepancy between the reported value of argc (2 - as expected)…
Ryan
  • 1,312
  • 3
  • 20
  • 40
2
votes
1 answer

Output of the Following Short argc & argv Code

#include using namespace std; int main(int argc, char* argv[]) { int i; i = 1; while (i < argc) { cout << argv[i] << endl; i = i + 1; } } Command line arguments are listed as b f i I'm just learning…
Mock
  • 359
  • 1
  • 3
  • 11
2
votes
2 answers

Store argv to an int array

I have code like this to store argv to a dynamically allocated int array: int *data; // pointer to array of integer numbers int size; // size of data array int main(int argc, char* argv[]) { // initialize array data size=argc; …
necroface
  • 3,365
  • 10
  • 46
  • 70
2
votes
3 answers

how can I test argc and then assign default values to argv[1]?

I need to give default behavior to a command line app if no arguments are entered. If no arguments are entered, I need the program to set argv[1][0] = '1' and argv[1][1] = '\0' for the null terminator. I keep getting a core dump when I try to…
user2993456
2
votes
2 answers

How can I remove the head of a main function?

I am trying to move some code from a separate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function. How can I create argc and argv by hand? Can someone give me some example…
napierzaza
  • 439
  • 5
  • 21
1 2
3
16 17