Download Command Line Arguments in C Programming and more Summaries Computer science in PDF only on Docsity!
COMPUTATIONAL THINKING FOR
STRUCTURED DESIGN
Topic:
COMMAND LINE ARGUMENTS
Mrs.U.Harita
Asst Professor
Department of BES-
AIM OF THE SESSION To Understand the concept of Command Line Arguments INSTRUCTIONAL OBJECTIVES This Session is designed to:
- To customize the behavior of a C program by passing input parameters at runtime.
- Facilitate the testing and debugging of C programs by allowing developers to specify input parameters easily and repeatedly during the development process. LEARNING OUTCOMES At the end of this session, you should be able to: 1.Understanding how to pass input parameters to a C program at runtime. 2.Familiarize with the main function's argc and argv arguments, and its usage.
INTRODUCTION
- (^) These are parameters passed to a program at runtime through the command line.
- They enable programs to handle a wide range of input data and configuration parameters without requiring prompts or input dialogs.
- This makes C programs more flexible and versatile, allowing them to perform different tasks and operations based on user input. KELF CTSD BES-
Session Description
- (^) It reduces the need for manual input and enabling users to perform tasks quickly and easily.
- (^) They also make it easier to test and debug programs by providing a way to automate the input data and configuration parameters used during testing.
- (^) They are useful when we want to control our program from outside rather than hard coding the values inside the program. KELF CTSD BES-
Sample Code : To Add two integers using Command Line Arguments #include <stdio.h> #include<stdlib.h> void main ( int argc, char *argv[] ) { int a,b,sum; if ( arg!=3) { return -1;} a=atoi(argv[1]); b=atoi(argv[2]); sum=a+b; printf(“%d”,sum); return 0} KLEF CTSD BES-
Program Execution Steps to execute the program 1 Go to the command prompt and type cmd 2 c:\users\harita>cd Documents c:\users\harita\cd Documents> cla 5 5 10 KELF CTSD BES-
REFERENCES FOR FURTHER LEARNING OF THE SESSION Reference Books:
- Mark Allen weiss, Data Structures and Algorithm Analysis in C, 2008, Third Edition, Pearson Education.
- Horowitz, Sahni, Anderson Freed, “Fundamentals of Data structures in C”, 2nd Edition2007.
- Robert Kruse, C. L. Tondo, Bruce Leung, Shashi Mogalla, “Data structures and Program Design in C”, 4th Edition- Sites and Web links:
- www.hackerrank.com
- www.codechef.com Reference Books:
- 1.) Brian W. Kernighan, Dennis M. Ritchie, “The C Programming Language: ANSI C Version”, 2/e, Prentice-Hall/Pearson Education-2005. 2.) E. Balagurusamy, “Programming in ANSI C” 4thed. Tata McGraw-Hill Education, 2008 Sites and Web links:
- https://www.w3schools.com/c/c_arrays.php
- https://www.includehelp.com/c-programs/c-programs-one-dimensional-arrays-problems-and-solutions.aspx https://technictiming.com/c-programming/array/