How to Write a Command Line Program in C? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In C, we can provide arguments to a program while running it from the command line interface. These arguments are called command-line arguments. In this article, we will learn how to write a command line program in C. How to Write a Command Line Program in C? Command line arguments are passed to the main() function. For that purpose, the main function should have the following signature: int main( int argc , char *argv[] ){ // Write your code } Here, argc is the number of arguments, and argv[] is the argument in the form of an array of strings. Note: The argv[0] always contains the source file name. C Program to Pass Command Line Arguments C // Program to demonstrate Command line arguments in C #include <stdio.h> #include <stdlib.h> int main(int argc, char* argv[]) { // code to calculate the sum of n numbers passed to CLA int i, sum = 0; // iterating the loop till the the number of // command-line arguments passed to the program // starting from index 1 for (i = 1; i < argc; i++) { sum = sum + atoi(argv[i]); } printf("Sum of %d numbers is : %d\n", argc - 1, sum); return 0; } Command Line Instruction // assume that the file name is solution ./solution 10 20 30 40 50 Output SUM of 5 numbers is: 150 Note: The command line arguments are separated by space so if you want to pass a space-separated string as a command line argument, then enclose them inside the "". To know more, refer to the article - Command Line Arguments in C Comment More infoAdvertise with us Next Article How to Write a Command Line Program in C? M msmriti Follow Improve Article Tags : C Programs C Language c-input-output C-Functions C Examples +1 More Similar Reads C Program To Print Your Own Name Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C program.ExamplesInput: name = "Rahul"Output: RahulExplanation: The program prints "Rahul" to the screen.Input: name = "Vikas"Output: VikasExplanation: The pro 3 min read C Program to Hide a Console Window On Startup Here in this article, we have created a console application that will write into a file. This console application will work in the background by hiding the console window. To ensure that the program or the console application is still running, we can see the live data appended in the text file creat 4 min read Build Your Own 'cat' Command in C for Linux You may have heard about cat command which is a Linux command. It stands for concatenate and plays an important role in Unix-like operating systems by helping to concatenate and display file contents. Despite the simple name, cat does a lot of work and goes beyond just putting those files together. 7 min read CLI programs in C for playing media and shut down the system Command Line Interface: CLI is a text-based user interface (UI) used to view and manage computer files.Command-line interfaces are also called command-line user interfaces, the console uses interfaces and characters uses interfaces.In programming, the user gives input during the execution of a progr 6 min read How to Read Input Until EOF in C? In C, reading input until the End of the File (EOF) involves reading input until it reaches the end i.e. end of file. In this article, we will learn various methods through which we can read inputs until EOF in C.Reading Input Until EOFRead Input Until EOF Using getchar()Read Input Until EOF Using f 5 min read Like