Your SlideShare is downloading. ×
Module 04 Command Line arguments in C
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Module 04 Command Line arguments in C

163
views

Published on

The presentation given at PCCOE, Nigdi, Pune by Prof. Tushar B Kute in workshop on "See through C". …

The presentation given at PCCOE, Nigdi, Pune by Prof. Tushar B Kute in workshop on "See through C".
http://tusharkute.com

Published in: Software

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
163
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. See through C Module 4 Command Line Arguments Tushar B Kute http://tusharkute.com
  • 2. The main( ) function ● So far, we have been defining the main() function to receive no arguments. ● Actually, the main( ) function can receive two arguments. ● To do that, the main( ) function should be defined as below. ● This is how arguments can be passed in at the command line. http://www.tusharkute.com 2 int main(int argc, char *argv[ ]) { … }
  • 3. ● From the command prompt, we can start running a program by typing its name and pressing ENTER. ● To pass arguments, we type in the program’s name followed by some arguments, then press ENTER. ● Below is an example from the Unix command prompt. Command Line Arguments % ./myprog % ./myprog 5 23
  • 4. argc and argv ● When the program is called from the command line with arguments, argc will contain the number of arguments. ● When the user types in arguments, the user separates each argument with a space. ● argv is an array of character strings. ● argv[1] is the character string containing the first argument, argv[2] the second, etc. ● Note: argv[0] contains the character string that is the name of the executable/binary.
  • 5. Example int main(int argc, char *argv[ ]) { int i; for (i = 1; i < argc; i++) printf("%s ", argv[i]); printf("n"); return 0; }
  • 6. Thank you This presentation is created using LibreOffice Impress 3.6.2.2

×