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

What are return values 2, 3 and 4 for?

Who can tell me what return 2 is exactly doing in this piece of code and why is it there? What about return 3 and return 4? The code you see is it not all, and basically is an exercise for the course cs50 where they propose a runoff election…
program101
  • 27
  • 4
-1
votes
1 answer

Unix/C command line arguments: Every single function has the same error what am I doing wrong?

I am supposed to take in arguments from the command line, to build a sample Unix-style 'ls' style program that lists the directory contents. I have pre-built functions given to me and I have to separate the code down into modularized header and c…
-1
votes
3 answers

C - Assigning value of argv to a variable

I am parsing the name of my .txt file as a parameter into the command line when calling the program. I want to assign the .txt file's name to a char variable. Here is my attempt: #include #include int main(int argc, char…
CS Beginner
  • 43
  • 2
  • 7
-1
votes
4 answers

What is the definition of an "argument in C"

I'm having some trouble reading a line of the code, and understanding what constitutes an argument in the context of this line of code. This is saved in a file called argv0.c #include #include int main(int argc, string argv[]) { …
Lim Dion
  • 5
  • 1
-1
votes
1 answer

Argc not working for my C Prog, getting coredump

I am writing a program to encrypt words. The thing is, the program works fine but when I put in 2/3 arg instead of 4, I'll get core dumped: This is my code: #include #include #include #include #include…
-1
votes
3 answers

Is there anyway to pass argc, argv outside of my main.cpp file?

I've never really used argc, argv[] for reading in files however the program requirements would like me to use them. My issue is I'm reading in the files in a header file and processing it there instead of main. Is there a way to use the argc,…
Zephers
  • 19
  • 4
-1
votes
1 answer

Using argc and argv in Caesar cipher in C

So, I am trying to use argc and argv in Caesars cipher in order to execute the program with just [./ key ;string] (e.g. ./ 13 Caesar). I have tried in lots of ways, although I must admit I am really lost here. I was thinking I should just use…
-1
votes
1 answer

Sprintf with pointers, constants and string formatting

I am new to C and I have had trouble simplifying this program. I am trying to initalize name once and strcat name to command once. It is a command line executable that takes two args and one optional arg for the filename "new py" or "new txt", or…
cwahls
  • 743
  • 7
  • 22
-1
votes
1 answer

How to check program start parameters from Windows Console?

At the start of my program, it should get path to the input file and path to the output file from the console. But if user give not required number of parameters or wrong parameters (with spaces for example, or without ".txt") it should give the…
Wojtek Smol
  • 57
  • 1
  • 2
-1
votes
1 answer

C++ pass a .txt file which has a function name and the parameter

I am working on a simple homework that requires me to pass a .txt file which contains 2 lines, the first is the function name, the second is a number, 3, or 9 for example. I am asking how to pass argv[0] as the function name and argv[ 1] as the…
pppear
  • 1
  • 2
-1
votes
3 answers

Why does argc returns 2 when only 1 argument was passed?

I wrote this simple code to understand how the argument system works. I dragged a textfile to the .exe file, and get 2 as output instead of 1 as i expected. Why 2? Is Arg 1 the .exe itself? How can i find out the filenames of the…
Black
  • 18,150
  • 39
  • 158
  • 271
-1
votes
2 answers

Having problems with rand() in c

I am trying to write a program that simulates a pyjama picking. The main function need to get the amount of pyjamas and the kind of pyjamas as arguments(3 kinds of pyjamas: cheap, regular and expensive). Each pyjama has a name, size and price, the…
Amnon Hanuhov
  • 21
  • 1
  • 3
  • 9
-1
votes
3 answers

Add argc for Windows cmd

Using Linux, when running a C++ program that takes a .txt file as an argc. i.e. int main(int argc, char *argv[]) I can simply compile it, then type ./a.out file.txt When using windows, after compiling it, how do i then run it including the file.txt…
Nathan
  • 13
  • 2
-1
votes
2 answers

Questions about strcpy overflows

I am using a simple main like this #include int main(int argc, char **argv) { char buf[256]; strcpy(buf, argv[1]); } I understand that if compiled, this main will produce 'argc' with a value of one, and argv[1] would not…
skrillac
  • 11
  • 1
  • 3
-1
votes
2 answers

How to scan through an array and do something once it catches a certain phrase

In C, suppose I need the code to do something when the user enters something like "-o" in the command line of linux involving argv and argc. More specifically if the file name starts with -o. How do I catch when a specific character string is…