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
1
vote
3 answers

Why we use argc -1?

This is a function to reverse a given arguments , why we used argc - 1 in this context,as long as there's not null to compare in int type, is it to subtract file name from count ? and if you could show other use of argc - 1 that would be great. int …
Question
  • 63
  • 7
1
vote
1 answer

Input Redirection - Cin not working with command line

I am tasked to write a simple program that reads in a file, and determines if the characters '(' '[' and '{' and "balanced". Meaning, There is a matching closing bracket/brace/parentheses for each opening one. I am having trouble with the input. We…
user14278552
1
vote
4 answers

Assignment of values to structs in C using command line

I am trying to set up an struct with many values using command line. I give those attributes when I execute the programme in the Ubuntu 18.04ls terminal of MS store. However I'm getting a problem because I cannot get access to those attributes…
diegogs_
  • 97
  • 9
1
vote
3 answers

I keep running into a segmentation error that I can't seem to be able to fix

For a course I'm taking I'm supposed to create a program that creates a simple ciphertext from plaintext using a key that the user inputs as a command line argument. Here's the code, it's written in C #include #include #include…
Kosh Rai
  • 13
  • 2
1
vote
1 answer

How exactly does argc work when I don't use quotation marks?

My code is very simple : #include int main(int argc, char **argv) { printf("%d\n", argc); return 0; } It prints 17 after I input ./a.out 1 2 3 + * Shouldn't it print 6 instead? The program's behavior is as expected if I put ''…
S.Sot
  • 321
  • 1
  • 7
1
vote
5 answers

Why is argv[argc] a pointer to NULL?

In the C standard ISO/IEC 9899:2018 (C18), §5.1.2.2.1 - "Program startup", is written: 2 - If they are declared, the parameters to the main function shall obey the following constraints: — argv[argc] shall be a null pointer. My Question is:…
1
vote
1 answer

How to pass arguments (argc, argv) from C++ code into a MatLab Mex file?

I'm trying to take some C++ code and place the appropriate MatLab mex function wrappers around it so that I can call my C++ as a MatLab function. My C++ code takes in 4 command line arguments using argc and argv. The C++ function call from the…
sdub0800
  • 139
  • 1
  • 9
1
vote
2 answers

Why won't my program accept the piped output of another program properly?

I have a C program compiled with 3 .c files. Essentially, that program prints out squares to the standard output based on x and y size input which I have defined in the main. The relevant code is below: void rush(int x, int y); int …
Thunderpurtz
  • 189
  • 2
  • 12
1
vote
1 answer

ARMv7 Assembly - Read from file and command line

I am having a problem reading some arguments from the command line when I call the program. I need to call it using ./try number string, for example: ./try 0 dfjjg When I run it I get a bus error. Can anybody help me? I'm new to assembly and it's…
Emil Popescu
  • 19
  • 1
  • 5
1
vote
3 answers

argc and argv for functions other than main

If I write a function such as this: void myfunc(const int argc, const char *argv[]) Will argc and argv automatically get their values from command line arguments, or will they need to be passed in their values from main?
user1519226
  • 77
  • 2
  • 12
1
vote
2 answers

Printing integers from command line arguments in C

I'm running my program with some command line arguments. But when I enter 10, 10, 10 and print them out, it prints out 49, 49, 49. Here's my code: int main(int argc, char *argv[]) { int seed = *argv[0]; int arraySize = *argv[1]; int…
namarino41
  • 123
  • 1
  • 15
1
vote
0 answers

'argc' has abnormal big value while debug in vc++

I wrote a code in VC++ 2013, and when debugging it, the 'argc' argument of main function gets an abnormal big value. A value higher than 2,000,000,000 always!! But every time has value different from previous run. I checked the 'Command Arguments'…
1
vote
0 answers

Accessing argc and argv from assembly

I encountered the following assembly version of a C code (Practical Malware Analysis by Michael Sikorski, Chapter 5). I simply do not understand how it accesses the command line parameters. cmp [ebp+argc], 3 ... mov eax, [ebp+argv] I understand…
robert
  • 3,539
  • 3
  • 35
  • 56
1
vote
1 answer

How do I write a message in the Protocol Buffer C++ tutorial?

I am new to Protocol Buffers and inexperienced with C++, I am trying to complete the tutorial at https://developers.google.com/protocol-buffers/docs/cpptutorial I've created the proto file mentioned in the tutorial and gotten addressbook.pb.h and…
jalconvolvon
  • 158
  • 1
  • 10
1
vote
4 answers

How do I benefit from argc and argv in C++, the standard way?

What is the standard way to retrive and check for the argc and argv and what is the best usage and how to do that in linux? Please provide examples. "I want to have a complex command-line options and I want to use them in my application" That what I…
malhobayyeb
  • 2,725
  • 11
  • 57
  • 91