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

Why is there an error when I try to run this code using command line arguments in shell?

I have a code called main.c that attempts to convert roman numerals into integers, and my code has to run via command line inputs, here is the code by the way: and I would like to know what is the simplest way to solve this issue. P.S. Yes, I know…
Deezel
  • 111
  • 6
0
votes
0 answers

mandatory and optional options with argc and argv

I want to create a programme that will have mandatory option and optional option. Mandatory: -d Optional: -h : help -m : launch an internal function with the value of the argument. ... (other optional option with or without…
eone
  • 1
0
votes
1 answer

How to check if there is NO command line arguments in C

I am creating simple calculator. I give arguments to be calculated as command line arguments. How do check if user gave no arguments at all? I Tried this, but i get segmentation fault: int main(int argc, char* argv[]){ if(argc == 0){ …
cosman
  • 23
  • 5
0
votes
1 answer

Reading argv[1] gives Segmentation Fault 11 although argc indicates there's two parameters

I stumbled upon an issue whereby if I want to read input arguments not inside the main method but inside another method into which argv is passed by reference I'm getting Segmentation Fault 11 for reading argument from argv[1] that succeeded in the…
Robert
  • 457
  • 7
  • 19
0
votes
3 answers

If argc is 1, can I still use argv[1], argv[2],... character arrays?

If there is no argument passed from the command line ie. if argc is 1, can we still allocate memory for argv[1],argv[2],..... and use those buffers for further experiments. If that is undefined behavior, can I still use it somehow?
Saurav Rai
  • 2,171
  • 1
  • 15
  • 29
0
votes
1 answer

Command line arguments not passing through correctly, argc always returning 1 and argc returning nullpointer on visual studio c++

I was recently working on a project for a class and was having a lot of problems with passing in command line arguments. I decided to test out with a really simple code I found online from geeksforgeeks to see if I could get any sort of command line…
0
votes
1 answer

How to read the Values of argc and argv in main function (c) from file?

I want for main function in c program, read argc and argv from file. How to read argv and argc from file in C language? For example: ./prog --test=cpu --prime=1000 run Change to: ./prog file.txt File.txt is: --test=cpu --prime=1000 run Prog is a…
Zahra Heydari
  • 55
  • 1
  • 4
0
votes
2 answers

How to utilize command line values in a loop

My code is supposed to get the factorial of a passed value. I spoke with my professor and he told me to use int argc, char* argv[] arguments. It compiles but will loop once and will only return the initial value. #include #include…
0
votes
0 answers

Accessing argc in main function of C program

I am currently trying to check the number of arguments supplied in the command line before my program executes. However, when I write argc within the main function, argc is underlined in red. When I hover over argc, I see a message saying, "Symbol…
10choices
  • 9
  • 3
0
votes
1 answer

Fill argv (and get argc) with a string to pass to other method

I receive from another method a string (I don’t know the size of this) and I want to fill my argv (and get argc) with this string to pass to other method and I don’t know how to do it. At the start of the string I set the name of my app so I have a…
skualo_
  • 3
  • 2
0
votes
1 answer

Difference between char* argv[] and string argv[] in C

What's the difference between: int main(int argc, char* argv[]) and int main(int argc, string argv[]) How does char* argv[] behave when compared to string argv[] and why do we need string argv[] ? Why is string argv[] not a pointer variable in…
Annie
  • 21
  • 2
  • 10
0
votes
0 answers

how the arguments are being sorted in this function?

sorry for not so-specific and not so-pro question , this code will sort any given parameters in lexicographic order, but it's still a little bit vague to me, if you have a little bit of time and patience and you could clarify step by step what's…
Question
  • 63
  • 7
0
votes
2 answers

Why does this final.exe file execute in an infinite loop instead of the specified number as below?

final.exe file. this executes infinitely or up to 50. #include #include #include int main(int argc, char *argv[]) { int i; if (argc < 2) { printf("ERROR: You need at least one argument.\n"); …
code_debug
  • 25
  • 4
0
votes
2 answers

C Function to retrieve argv contents to string

I'm not going to have the time to submit my solution any way, yet I'm so frustrated. I am coding a function that would take argv on execution and concat its contents in a string with commands separated by \n Something like this "./a.out \n a \n b \n…
Majd
  • 328
  • 4
  • 12
0
votes
2 answers

How can I pass a command line argument which contains space character to my C++ program?

We can access command line arguments via argv code in C++, I know that. But the problem is, if an argument contains space, then my program works like as if there are two parameters. For example if the argument is foo bar, my program sees two…
DrakeMcCain
  • 129
  • 3
  • 14