SlideShare a Scribd company logo
1 of 10
CREATED BY K. VICTOR BABU
COMPUTATIONAL THINKING FOR
STRUCTURED DESIGN
Topic:
COMMAND LINE ARGUMENTS
Mrs.U.Harita
Asst Professor
Department of BES-1
CREATED BY K. VICTOR BABU
AIM OF THE SESSION
To Understand the concept of Command Line Arguments
INSTRUCTIONAL OBJECTIVES
This Session is designed to:
1. To customize the behavior of a C program by passing input parameters at runtime.
2. 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.
CREATED BY K. VICTOR BABU
Command Line Arguments
Consider the declaration
int add(int a, int b);
add is a user defined function.
Two integers are passed as parameters to the function add()
Have you ever passed arguments to main() ?
Will main() accept any arguments?
KELF CTSD BES-1
CREATED BY K. VICTOR BABU
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-1
CREATED BY K. VICTOR BABU
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-1
CREATED BY K. VICTOR BABU
Command Line arguments
Syntax:
int main(int argc,char*argv[]);
The first argument i.e argc counts the number of arguments in the
command line
The argument argv[] is a pointer array that holds the pointer of type
char that points to arguments passed to the program.
KELF CTSD BES-1
CREATED BY K. VICTOR BABU
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}
KELF CTSD BES-1
CREATED BY K. VICTOR BABU
Program Execution
Steps to execute the program
1 Go to the command prompt and type cmd
2 c:usersharita>cd Documents
c:usersharitacd Documents> cla 5 5
10
KELF CTSD BES-1
CREATED BY K. VICTOR BABU
Command Line arguments – Sample Code 2
#include <stdio.h>
void main (int argc, char *argv[] )
{
print f("Program name is: %sn", argv[0]);
if (argc < 2)
{
printf ("No argument passed through command line.n");
}
else
{
printf ("First argument is: %sn", argv [1]); } }
KELF CTSD BES-1
CREATED BY K. VICTOR BABU
REFERENCES FOR FURTHER LEARNING OF THE SESSION
Reference Books:
1. Mark Allen weiss, Data Structures and Algorithm Analysis in C, 2008, Third Edition, Pearson Education.
2. Horowitz, Sahni, Anderson Freed, “Fundamentals of Data structures in C”, 2nd Edition2007.
3. Robert Kruse, C. L. Tondo, Bruce Leung, Shashi Mogalla, “Data structures and Program Design in C”, 4th Edition-2007
Sites and Web links:
1. www.hackerrank.com
2. www.codechef.com
Reference Books:
1. 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:
1) https://www.w3schools.com/c/c_arrays.php
2) https://www.includehelp.com/c-programs/c-programs-one-dimensional-arrays-problems-and-solutions.aspx
https://technictiming.com/c-programming/array/

More Related Content

Similar to 23_1-Command line Arguments.pptx

Similar to 23_1-Command line Arguments.pptx (20)

C FUNCTIONS
C FUNCTIONSC FUNCTIONS
C FUNCTIONS
 
Intro
IntroIntro
Intro
 
Presentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakurPresentation on C language By Kirtika thakur
Presentation on C language By Kirtika thakur
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
C Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.comC Programming Tutorial - www.infomtec.com
C Programming Tutorial - www.infomtec.com
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
C introduction by piyushkumar
C introduction by piyushkumarC introduction by piyushkumar
C introduction by piyushkumar
 
Unit 2 ppt
Unit 2 pptUnit 2 ppt
Unit 2 ppt
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
FUNCTIONS.pptx
FUNCTIONS.pptxFUNCTIONS.pptx
FUNCTIONS.pptx
 
Introduction to c++
Introduction to c++Introduction to c++
Introduction to c++
 
Intro to c++
Intro to c++Intro to c++
Intro to c++
 
C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
490450755-Chapter-2.ppt
490450755-Chapter-2.ppt490450755-Chapter-2.ppt
490450755-Chapter-2.ppt
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Basics of c Nisarg Patel
Basics of c Nisarg PatelBasics of c Nisarg Patel
Basics of c Nisarg Patel
 
Ocs752 unit 4
Ocs752   unit 4Ocs752   unit 4
Ocs752 unit 4
 

Recently uploaded

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 

Recently uploaded (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 

23_1-Command line Arguments.pptx

  • 1. CREATED BY K. VICTOR BABU COMPUTATIONAL THINKING FOR STRUCTURED DESIGN Topic: COMMAND LINE ARGUMENTS Mrs.U.Harita Asst Professor Department of BES-1
  • 2. CREATED BY K. VICTOR BABU AIM OF THE SESSION To Understand the concept of Command Line Arguments INSTRUCTIONAL OBJECTIVES This Session is designed to: 1. To customize the behavior of a C program by passing input parameters at runtime. 2. 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.
  • 3. CREATED BY K. VICTOR BABU Command Line Arguments Consider the declaration int add(int a, int b); add is a user defined function. Two integers are passed as parameters to the function add() Have you ever passed arguments to main() ? Will main() accept any arguments? KELF CTSD BES-1
  • 4. CREATED BY K. VICTOR BABU 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-1
  • 5. CREATED BY K. VICTOR BABU 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-1
  • 6. CREATED BY K. VICTOR BABU Command Line arguments Syntax: int main(int argc,char*argv[]); The first argument i.e argc counts the number of arguments in the command line The argument argv[] is a pointer array that holds the pointer of type char that points to arguments passed to the program. KELF CTSD BES-1
  • 7. CREATED BY K. VICTOR BABU 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} KELF CTSD BES-1
  • 8. CREATED BY K. VICTOR BABU Program Execution Steps to execute the program 1 Go to the command prompt and type cmd 2 c:usersharita>cd Documents c:usersharitacd Documents> cla 5 5 10 KELF CTSD BES-1
  • 9. CREATED BY K. VICTOR BABU Command Line arguments – Sample Code 2 #include <stdio.h> void main (int argc, char *argv[] ) { print f("Program name is: %sn", argv[0]); if (argc < 2) { printf ("No argument passed through command line.n"); } else { printf ("First argument is: %sn", argv [1]); } } KELF CTSD BES-1
  • 10. CREATED BY K. VICTOR BABU REFERENCES FOR FURTHER LEARNING OF THE SESSION Reference Books: 1. Mark Allen weiss, Data Structures and Algorithm Analysis in C, 2008, Third Edition, Pearson Education. 2. Horowitz, Sahni, Anderson Freed, “Fundamentals of Data structures in C”, 2nd Edition2007. 3. Robert Kruse, C. L. Tondo, Bruce Leung, Shashi Mogalla, “Data structures and Program Design in C”, 4th Edition-2007 Sites and Web links: 1. www.hackerrank.com 2. www.codechef.com Reference Books: 1. 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: 1) https://www.w3schools.com/c/c_arrays.php 2) https://www.includehelp.com/c-programs/c-programs-one-dimensional-arrays-problems-and-solutions.aspx https://technictiming.com/c-programming/array/