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

C Program Segmentation Fault main()

I am novice to C programming and I have written a code to a requirement specification but I am consistently getting Segmentation Fault and unable to proceed ahead. If the file name is 'code.c' and it runs with an error of not passing the argument…
user3337714
  • 663
  • 1
  • 7
  • 25
1
vote
1 answer

How to pass escape sequence like tab and newline char as command line argument in C programming getopt_long?

I almost reached end of my code, after a lot of search I didn't find solution no where, I want to supply escape sequence like '\t', '\n' to my program like how awk and perl program takes, and finally I want to use them as printf or sprintf format…
user3637224
  • 585
  • 1
  • 3
  • 22
1
vote
2 answers

Do the names of the args passed to main() matter

I know that to use command line arguments in C you do something like this: int main(int argc, char **argv) { //use argc and argv } Today I was thinking about it and I realized I have never not seen them called argc and argv. Is it a requirement…
user3282276
  • 3,674
  • 8
  • 32
  • 48
1
vote
1 answer

why this segmentation fault (core dumped) ??? int main (int argc, char *argv[])

int main (int argc, char *argv[]) { int a, b, quo, rest; void division(int dividendo, int divisor, int *ptr_quociente, int *ptr_resto) { *ptr_quociente=dividendo/divisor; *ptr_resto=dividendo%divisor; } …
Bryant2
  • 49
  • 8
1
vote
0 answers

Putting *argv[ ] into character array

I am trying to take the arguments put on the command line and put them into an array of integers so I can do computations with them. What I am doing to solve this is taking arguments starting at argv[1] (I dont need ./a.out) and putting them into a…
KS7X
  • 332
  • 2
  • 15
1
vote
1 answer

argc and argv aren't running

Here is what the geany says. Help appreciated. rec_pattern_printing.c:5: error: syntax error before '*' token rec_pattern_printing.c: In function `main': rec_pattern_printing.c:8: error: `argc' undeclared (first use in this…
Sahir
  • 329
  • 1
  • 2
  • 9
1
vote
3 answers

Checking if argv[i] is a valid integer, passing arguments in main

I'm trying to make sure all arguments passed to main are valid integers, and if not, I'll print an error. For example, if I have an executable named total, I would enter total 1 2 3 4. I want to print an error if there's an invalid integer, so if I…
user1940516
  • 41
  • 1
  • 3
  • 6
1
vote
2 answers

char **argv[] segfaults when trying to get input from the command line

I'm trying to do the most basic of things and am hitting a brick wall. I'm trying to read in a file name from the command line to use later in my program, but I can't even seem to extract the name from argv[]. Here's the code: #include…
Fab Castel
  • 552
  • 5
  • 18
1
vote
1 answer

Popping and printing argc from the stack

According to this paper and a few stackoverflow posts, argc is at the top of the stack and argv is below it. I've tried about 3-4 different ways of doing it: Popping it into an initialized variable (.data) - output done by calling printf. Popping…
user1807879
  • 151
  • 2
  • 8
1
vote
4 answers

Command-line arguments

I am aware that the main function can take two arguments: int argc and char* argv[]. This is well documented. However the main function can also take a third argument. Does anyone one know what this argument is?
1
vote
4 answers

why is argc returning 6 as opposed to 3?

I have following program and i am passing it 2 arguments at the command line as shown below. I was expecting the argc to be 3, but it prints it as 6. why? #include #include #include using namespace std; void…
Jimm
  • 8,165
  • 16
  • 69
  • 118
1
vote
6 answers

setting variables with argv

Here is a minimal working example describing my current situation. The file main.cpp #include void print_from_external_file(); using namespace std; int main( int argc, char* argv[]) { print_from_external_file(); return…
BillyJean
  • 1,537
  • 1
  • 22
  • 39
0
votes
1 answer

C Programming - Command Line Arg - Trying to take an IP Address

Our assignment is to have a server-client model.... We're supposed to check for a command line arg, if there is not one(argc = 1), we set up as a server. otherwise we use the argv[1] to setup the client socket... It seems to run fine if I just use…
ChrisB92
  • 45
  • 1
  • 7
0
votes
0 answers

Segmentation Fault (core dumped): Error when providing no argument

Code implementation I was trying to implement the code such way that it takes only a command line argument, and if not provided or provided more than 1, it prints out an error message. But it is showing "segmentation fault(core dumped)" whenever I…
0
votes
1 answer

How do i take integers from a file and place them in an int vector?

I am trying to take a text file and take the integers inside the file and transfer them into a vector in which can be read into different functions. This is what i have so far: int main(int argc, char *argv[] ) { vector buff; argv[1] =…
user977154
  • 1,045
  • 4
  • 19
  • 39