Difference between revisions of "Advance-C/C2/Command-line-arguments-in-C/English-timed"
From Script | Spoken-Tutorial
PoojaMoolya (Talk | contribs) |
Sandhya.np14 (Talk | contribs) |
||
Line 6: | Line 6: | ||
|- | |- | ||
| 00:01 | | 00:01 | ||
− | |Hello and welcome to the spoken tutorial on''' Command Line Arguments.''' | + | |Hello and welcome to the '''spoken tutorial''' on''' Command Line Arguments.''' |
|- | |- | ||
| 00:07 | | 00:07 | ||
− | |In this tutorial, we will learn about '''main function with arguments''' with an example. | + | |In this tutorial, we will learn about '''main''' function with '''arguments''', with an example. |
|- | |- | ||
| 00:15 | | 00:15 | ||
− | |For this tutorial I am using '''Ubuntu Operating system version 11.10''' and '''gcc Compiler version 4.6.1 | + | |For this tutorial, I am using '''Ubuntu Operating system''' version '''11.10''' and '''gcc Compiler''' version '''4.6.1''' on Ubuntu. |
|- | |- | ||
Line 22: | Line 22: | ||
|- | |- | ||
| 00:33 | | 00:33 | ||
− | | If not, for relevant tutorials please visit our website which is as shown. | + | | If not, for relevant tutorials, please visit our website which is as shown. |
|- | |- | ||
Line 30: | Line 30: | ||
|- | |- | ||
| 00:45 | | 00:45 | ||
− | |Filename is '''main hyphen with hyphen args.c''' | + | |Filename is ''''main hyphen with hyphen args.c''''. |
|- | |- | ||
Line 38: | Line 38: | ||
|- | |- | ||
| 00:53 | | 00:53 | ||
− | |These are the '''header | + | |These are the '''header''' files. '''stdio.h '''defines '''core input''' and '''output''' functions. |
|- | |- | ||
| 01:01 | | 01:01 | ||
|'''stdlib.h header file''' defines- | |'''stdlib.h header file''' defines- | ||
− | * '''Numeric conversion function''' | + | * '''Numeric conversion function''' |
− | * '''Pseudo-random numbers''' | + | * '''Pseudo-random numbers''' |
− | * '''Generation function''' | + | * '''Generation function''' |
− | * '''Memory allocation''' | + | * '''Memory allocation''' |
* '''Process control functions'''. | * '''Process control functions'''. | ||
|- | |- | ||
|01:16 | |01:16 | ||
− | |This is our '''main function.''' Inside this, we have passed ''' | + | |This is our ''''main' function.''' Inside this, we have passed two '''arguments'''- |
− | '''int argc, char asterisk asterisk argv''' (**argv) | + | '''int argc, char asterisk asterisk argv''' (**argv). |
|- | |- | ||
Line 76: | Line 76: | ||
|- | |- | ||
| 01:53 | | 01:53 | ||
− | |'''Index 2''' will be the second '''argument''' passed to the program | + | |'''Index 2''' will be the second '''argument''' passed to the program and so on. |
|- | |- | ||
Line 84: | Line 84: | ||
|- | |- | ||
| 02:05 | | 02:05 | ||
− | |This will display the | + | |This will display the first argument passed to the program. |
|- | |- | ||
Line 92: | Line 92: | ||
|- | |- | ||
| 02:13 | | 02:13 | ||
− | |''' | + | |''''while' condition''' will decrement the number of '''arguments'''. |
|- | |- | ||
Line 100: | Line 100: | ||
|- | |- | ||
| 02:23 | | 02:23 | ||
− | |At the end we have''' return 0 '''statement. | + | |At the end, we have''' return 0 '''statement. |
|- | |- | ||
Line 108: | Line 108: | ||
|- | |- | ||
| 02:35 | | 02:35 | ||
− | |Type:''' gcc space main hyphen with hyphen args.c space hyphen o space args'''. Press''' Enter''' | + | |Type:''' gcc space main hyphen with hyphen args.c space hyphen o space args'''. Press''' Enter'''. |
|- | |- | ||
Line 117: | Line 117: | ||
| 02:54 | | 02:54 | ||
|You can see the output as: | |You can see the output as: | ||
− | + | "Total number of arguments are 1". | |
− | + | "The first argument is null" | |
− | + | "arguments are ./args" | |
− | + | ||
− | + | ||
|- | |- | ||
Line 129: | Line 127: | ||
|- | |- | ||
| 03:11 | | 03:11 | ||
− | |'''Total number of arguments are 1''' as the | + | |'''Total number of arguments are 1''' as the zeroth argument is the executable filename itself. |
|- | |- | ||
| 03:19 | | 03:19 | ||
− | |'''The first argument is (null) '''as we have not passed any | + | |'''The first argument is (null) '''as we have not passed any argument to the program. |
|- | |- | ||
| 03:26 | | 03:26 | ||
− | |'''Arguments''' are only one | + | |'''Arguments''' are only one i.e. '''dot slash args'''. |
|- | |- | ||
| 03:31 | | 03:31 | ||
− | |Now let us execute again | + | |Now let us execute again. |
|- | |- | ||
| 03:34 | | 03:34 | ||
− | |Press the | + | |Press the up-arrow key '''space''' type: '''Sunday space Monday space Tuesday'''. Press '''Enter''' |
|- | |- | ||
Line 154: | Line 152: | ||
'''The first argument is Sunday ''' | '''The first argument is Sunday ''' | ||
− | ''' | + | '''Arguments are ./args ''' '''Sunday Monday ''' and '''Tuesday '''. |
|- | |- | ||
Line 166: | Line 164: | ||
|- | |- | ||
| 04:14 | | 04:14 | ||
− | |The '''first argument''' is '''Sunday ''' | + | |The '''first argument''' is '''Sunday '''. |
|- | |- | ||
| 04:17 | | 04:17 | ||
− | |The ''' | + | |The '''zeroth argument''' always gives executable filename. |
|- | |- | ||
| 04:22 | | 04:22 | ||
− | |'''Sunday''' is assigned to | + | |'''Sunday''' is assigned to first argument. |
|- | |- | ||
| 04:25 | | 04:25 | ||
− | |'''Monday '''is assigned to | + | |'''Monday '''is assigned to second argument. |
|- | |- | ||
| 04:28 | | 04:28 | ||
− | |'''Tuesday '''is assigned to | + | |'''Tuesday '''is assigned to third argument. |
|- | |- | ||
Line 190: | Line 188: | ||
|- | |- | ||
| 04:37 | | 04:37 | ||
− | |In this tutorial we learnt | + | |In this tutorial, we learnt: |
* '''Command line arguments''' | * '''Command line arguments''' | ||
* '''argc''' | * '''argc''' | ||
− | * '''argv''' | + | * '''argv'''. |
|- | |- | ||
Line 201: | Line 199: | ||
|- | |- | ||
| 04:51 | | 04:51 | ||
− | |Watch the video available at the link shown below | + | |Watch the video available at the link shown below. |
|- | |- | ||
| 04:54 | | 04:54 | ||
− | |It | + | |It summarizes the Spoken Tutorial project. |
|- | |- | ||
| 04:57 | | 04:57 | ||
− | |If you do not have good bandwidth, you can download and watch it | + | |If you do not have good bandwidth, you can download and watch it. |
|- | |- | ||
| 05:02 | | 05:02 | ||
− | |The Spoken Tutorial Project | + | |The Spoken Tutorial Project team: * Conducts workshops using spoken tutorials. |
|- | |- | ||
| 05:08 | | 05:08 | ||
− | |Gives certificates to those who pass an online test. For more details, please write to '''contact@spoken-tutorial.org''' | + | |* Gives certificates to those who pass an online test. For more details, please write to '''contact@spoken-tutorial.org''' |
|- | |- | ||
| 05:18 | | 05:18 | ||
− | |Spoken Tutorial Project is a part of the Talk to a Teacher project | + | |'''Spoken Tutorial''' Project is a part of the '''Talk to a Teacher''' project. |
|- | |- | ||
| 05:22 | | 05:22 | ||
− | |It is supported by the National Mission on Education through ICT, MHRD, Government of India | + | |It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
|- | |- | ||
| 05:30 | | 05:30 | ||
− | |More information on this | + | |More information on this mission is available at: '''http://spoken-tutorial.org\NMEICT-Intro'''. |
|- | |- | ||
| 05:36 | | 05:36 | ||
− | |This is Ashwini Patil from IIT Bombay signning off. | + | |This is Ashwini Patil from IIT Bombay, signning off. |
Thank you for joining. | Thank you for joining. | ||
|} | |} |
Revision as of 12:11, 3 December 2015
|
|
---|---|
00:01 | Hello and welcome to the spoken tutorial on Command Line Arguments. |
00:07 | In this tutorial, we will learn about main function with arguments, with an example. |
00:15 | For this tutorial, I am using Ubuntu Operating system version 11.10 and gcc Compiler version 4.6.1 on Ubuntu. |
00:27 | To follow this tutorial, you should be familiar with C tutorials. |
00:33 | If not, for relevant tutorials, please visit our website which is as shown. |
00:39 | Let us start with our program. I have a code file. I will open it. |
00:45 | Filename is 'main hyphen with hyphen args.c'. |
00:50 | Let me explain the program. |
00:53 | These are the header files. stdio.h defines core input and output functions. |
01:01 | stdlib.h header file defines-
|
01:16 | This is our 'main' function. Inside this, we have passed two arguments-
int argc, char asterisk asterisk argv (**argv). |
01:28 | “argc” refers to the number of command line arguments passed to the program. |
01:34 | This includes the actual name of the program. |
01:38 | argv contains actual arguments starting from index 0. |
01:44 | Index 0 is the name of the program. |
01:48 | Index 1 will be the first argument passed to the program. |
01:53 | Index 2 will be the second argument passed to the program and so on. |
01:59 | This statement will display the total number of arguments passed to the program. |
02:05 | This will display the first argument passed to the program. |
02:09 | 1 represents the argument at index 1. |
02:13 | 'while' condition will decrement the number of arguments. |
02:18 | This statement will print all the arguments passed to the program. |
02:23 | At the end, we have return 0 statement. |
02:27 | Let us open the terminal by pressing Ctrl+Alt+T keys simultaneously on your keyboard. |
02:35 | Type: gcc space main hyphen with hyphen args.c space hyphen o space args. Press Enter. |
02:49 | Type: dot slash args. Press Enter. |
02:54 | You can see the output as:
"Total number of arguments are 1". "The first argument is null" "arguments are ./args" |
03:06 | Command line arguments are given during execution. |
03:11 | Total number of arguments are 1 as the zeroth argument is the executable filename itself. |
03:19 | The first argument is (null) as we have not passed any argument to the program. |
03:26 | Arguments are only one i.e. dot slash args. |
03:31 | Now let us execute again. |
03:34 | Press the up-arrow key space type: Sunday space Monday space Tuesday. Press Enter |
03:47 | Now we can see the output:
Total number of arguments are 4 The first argument is Sunday Arguments are ./args Sunday Monday and Tuesday . |
04:04 | Let me explain the output. |
04:06 | Total number of arguments are 4 as ./args, Sunday, Monday and Tuesday. |
04:14 | The first argument is Sunday . |
04:17 | The zeroth argument always gives executable filename. |
04:22 | Sunday is assigned to first argument. |
04:25 | Monday is assigned to second argument. |
04:28 | Tuesday is assigned to third argument. |
04:31 | This brings us to the end of this tutorial. Let us summarize. |
04:37 | In this tutorial, we learnt:
|
04:45 | As an assignment, execute the program with different arguments. |
04:51 | Watch the video available at the link shown below. |
04:54 | It summarizes the Spoken Tutorial project. |
04:57 | If you do not have good bandwidth, you can download and watch it. |
05:02 | The Spoken Tutorial Project team: * Conducts workshops using spoken tutorials. |
05:08 | * Gives certificates to those who pass an online test. For more details, please write to contact@spoken-tutorial.org |
05:18 | Spoken Tutorial Project is a part of the Talk to a Teacher project. |
05:22 | It is supported by the National Mission on Education through ICT, MHRD, Government of India. |
05:30 | More information on this mission is available at: http://spoken-tutorial.org\NMEICT-Intro. |
05:36 | This is Ashwini Patil from IIT Bombay, signning off.
Thank you for joining. |