Difference between revisions of "Advance-C/C2/Command-line-arguments-in-C/English-timed"
From Script | Spoken-Tutorial
Sandhya.np14 (Talk | contribs) |
Sandhya.np14 (Talk | contribs) |
||
Line 160: | Line 160: | ||
|- | |- | ||
| 04:06 | | 04:06 | ||
− | |Total number of arguments are 4 as '''./args, Sunday, Monday''' and '''Tuesday.''' | + | |Total number of arguments are 4 as- '''./args, Sunday, Monday''' and '''Tuesday.''' |
|- | |- | ||
| 04:14 | | 04:14 | ||
− | |The | + | |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 first argument. |
|- | |- | ||
| 04:25 | | 04:25 | ||
− | | | + | |"Monday" is assigned to second argument. |
|- | |- | ||
| 04:28 | | 04:28 | ||
− | | | + | |"Tuesday" is assigned to third argument. |
|- | |- |
Revision as of 12:13, 4 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. |