Array indexing in C is zero-based. If argc is 2, then argv[0] is the path to your executable, and argv[1] is the first argument.

The other problem you have is you cannot compare char* strings with ==, and you cannot have a single character '-S'. Yes, single-quotes is for a character, and double-quotes is for a string.

Use strcmp() from <string.h> as follows:

if (strcmp(argv[1], "-S") == 0) {
    printf("Hola Mundo in Spanish\n");
}
Answer from paddy on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › c++ › command-line-arguments-in-c-cpp
Command Line Arguments in C - GeeksforGeeks
5 days ago - Command Line Arguments in C are values passed to a C program when it is executed from the command line, allowing users to provide input without modifying the source code.
Discussions

How can i do this, Command Line Arguments in c - Stack Overflow
I am learning C, and I am in the part about the arguments: int argc, char *argv[]. I am trying to make a code that prints a result according to the argument put in console. For example: ./a.out -E to More on stackoverflow.com
🌐 stackoverflow.com
Command line arguments in C
Argv is an array where each element is one part of the command used to start the program. For example if you run ./program hello world then argv contains three arguments, ./program, hello, and world. Since there is no reliable way to get the size of an array in C, your program also gets argc, which is just the number of elements in the array argv. In the example above, argc would be 3. More on reddit.com
🌐 r/cs50
6
7
July 22, 2023
3 Ways To Parse Command Line Arguments in C++: Quick, Do-It-Yourself, Or Comprehensive
boost::program_options works well enough for me that I haven't gone looking for anything better. The syntax is a bit unfortunate, but it doesn't take that much to get used to. Apparently it can be used to read environment variables too, although I've never used it for that. More on reddit.com
🌐 r/cpp
31
53
November 4, 2021
Command Line Flags in C++, A Minimalist's Guide
Completely unrelated: that is a beautiful-looking blog theme. I love old-timey typography! More on reddit.com
🌐 r/cpp
50
73
February 13, 2022
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_command_line_arguments.htm
Command Line Arguments in C
You pass all the command line arguments separated by a space, but if the argument itself has a space, then you can pass such arguments by putting them inside double quotes (" ") or single quotes (' ').
🌐
Caltech
users.cms.caltech.edu › ~mvanier › CS11_C › misc › cmdline_args.html
CS 11 C track: Processing command-line arguments
The C language has fairly standardized conventions about how to process command-line arguments, which I summarize here. I will also give some advice on the most effective ways to do this. ... Optional command-line arguments have a dash (-) before them. Optional command-line arguments are identified by placing a dash (-) before the optional argument’s name. For instance, the ls command in Unix will give a long form output if the command-line argument -l is provided (the $ is the unix prompt):
🌐
University of Utah
users.cs.utah.edu › ~germain › PPS › Topics › C_Language › command_line_args.html
The C Programming Language - Command Line Arguments
The C program must "parse" the command line arguments (which are given to the program as a list of strings) and transform this type of data into a form useful in "guiding" the program to execute in the manner specified by the user.
Find elsewhere
🌐
Substack
alexanderobregon.substack.com › alexander obregon's substack › command line arguments and main in c
Command Line Arguments and main in C
February 11, 2026 - Learn how C maps command line arguments into argc and argv in main and how memory, exit codes, getopt, and argp tie results back to the shell.
🌐
Suchprogramming
suchprogramming.com › command-line-c
Such Programming - Command Line Arguments in C
January 24, 2018 - $ ./classic well hello there Argument Count: 4 argv is at 0x7ffc923396b8 0 at 0x7ffc92339f4d: ./classic 1 at 0x7ffc92339f57: well 2 at 0x7ffc92339f5c: hello 3 at 0x7ffc92339f62: there 4 at (nil): (null) The first argument is the name of the program as it was executed, the remaining argc - 1 are the command line arguments to that program. They are most often accessed using an index operator [i] as was done here, though usually i < argc; is used in the for loop condition to skip the null element that terminates the array.
🌐
Scaler
scaler.com › home › topics › command line arguments in c
Command Line Arguments in C - Scaler Topics
March 1, 2022 - When a program starts execution without user interaction, command-line arguments are used to pass values or files to it. ... When the main function of a program contains arguments, then these arguments are known as Command Line Arguments. The main function can be created with two methods: first with no parameters (void) and second with two parameters.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Command_002dline-Parameters.html
Command-line Parameters (GNU C Language Manual)
Here is an example of accessing the command-line parameters, retrieving the program’s name and checking for the standard --version and --help options: #include <string.h> /* Declare strcmp. */ int main (int argc, char *argv[]) { char *program_name = argv[0]; for (int i = 1; i < argc; i++) { if (!strcmp (argv[i], "--version")) { /* Print version information and exit.
🌐
OnlineGDB
onlinegdb.com › online_c_compiler
Online C Compiler - online editor
close ad [x] Done · input · stdout · stderr · Debug Console · Command line arguments: Standard Input: Interactive Console Text · × · start pause continue step over step into step out help · × · If your program is reading input from standard input and you forgot to provide input via stdin.
🌐
Northern Illinois University
faculty.cs.niu.edu › ~mcmahon › CS241 › Notes › command_line_arguments.html
Command Line Arguments
The program can get this value (as a C string) and set a program variable (as an integer) so that it can control the number of lines displayed. ... They are passed to the main() function as arguments.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › pdf › c_command_line_arguments.pdf pdf
C - Command Line Arguments
executed. These values are called command line arguments and many times they are · important for your program specially when you want to control your program from outside instead · of hard coding those values inside the code. The command line arguments are handled using main function arguments where argc refers to ·
🌐
BtechSmartClass
btechsmartclass.com › c_programming › C-Command-Line-Arguments.html
C Tutorials - Command Line Arguments in C Programming Language
Generally, the command line arguments can be understood as follows... Command line arguments are the parameters passing to main() method from the command line. When command line arguments are passed main() method receives them with the help of two formal parameters and they are, ... int argc ...
🌐
Valve Developer Community
developer.valvesoftware.com › wiki › SteamCMD
SteamCMD - Valve Developer Community
April 28, 2026 - Note: If this does not work, try putting it like "+app_update 90 -beta beta" instead. Append the commands to the command line prefixed with plus characters, e.g.:
🌐
HowStuffWorks
computer.howstuffworks.com › tech › computer software › programming
Command Line Arguments - The Basics of C Programming | HowStuffWorks
March 8, 2023 - The argc integer contains a count of the number of parameters. This particular piece of code types out the command line parameters. To try this, compile the code to an executable file named aaa and type aaa xxx yyy zzz. The code will print the command line parameters xxx, yyy and zzz, one per line. The char *argv[] line is an array of pointers to string.
🌐
Elecdude
elecdude.com › 2012 › 12 › comman-line-arguments-in-c.html
COMMAND LINE ARGUMENTS IN C ~ ElecDude
December 25, 2012 - The character array argv[] has ... syntax of command line argument is given below #include <headerfile.h> void main(int argc ,char ** argv[]) { } => let us see an example for command line argument ....
🌐
W3Schools
w3schools.in › c-programming › command-line-arguments
Command Line Arguments in C
To use this concept in your program, you have to understand the complete declaration of how the main() function works with the command-line argument to fetch values that earlier took no arguments with it (main() without any argument). So you can program the main() in such a way that it can essentially accept two arguments where the first argument denotes the number of command line arguments and the second denotes the complete list of every command line argument.
🌐
Medium
medium.com › @khimaja3127 › essential-techniques-for-mastering-command-line-arguments-in-c-da779bf890b8
Essential Techniques for Mastering Command Line Arguments in C | by k Himaja | Medium
September 16, 2024 - Command line arguments are values that are passed to a C program when it is executed from the command line. They are typically used to provide input data, configure program settings, or select specific functionalities.
🌐
Scribd
scribd.com › document › 823315677 › Command-Line-Arguments-in-C
Command Line Arguments in C | PDF | Parameter (Computer Programming) | Integer (Computer Science)
Command Line Arguments in C - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free.