Difference between revisions of "C-and-C++/C3/String-Library-Functions/English-timed"
From Script | Spoken-Tutorial
(Created page with ' {| border=1 || ''Time''' || '''Narration''' |- | 00:02 | Welcome to the spoken-tutorial on String Library Functions in C |- | 00:07 | In this tutorial, we will learn, |- | …') |
|||
Line 1: | Line 1: | ||
− | |||
{| border=1 | {| border=1 | ||
|| ''Time''' | || ''Time''' | ||
Line 74: | Line 73: | ||
|- | |- | ||
| 01:29 | | 01:29 | ||
− | | Now we will see | + | | Now we will see strncmp function, the syntax for this is strncmp (char str1, char str2 and int n) |
|- | |- |
Revision as of 11:42, 11 October 2013
Time' | Narration |
00:02 | Welcome to the spoken-tutorial on String Library Functions in C |
00:07 | In this tutorial, we will learn, |
00:10 | String Library Functions |
00:12 | We will do this with the help of some examples |
00:15 | To record this tutorial, I am using |
00:18 | Ubuntu Operating System version 11.10, |
00:23 | gcc Compiler Version 4.6.1 |
00:27 | Let us start with an introduction to string library functions. |
00:31 | These are the group of functions implementing operations on strings. |
00:37 | Various operations such as copying, concatenation, searching etc are supported. |
00:45 | Let us see some of the string library functions |
00:49 | Here we have the strncpy function |
00:52 | The syntax for this is strncpy(char str1, char str2, int n ) |
01:02 | It copies first n characters of string str2 into string str1. |
01:10 | eg. char strncpy(char hello, char world, 2); |
01:17 | The output will be ;Wollo |
01:21 | Here we have Wo fromt the string 2 and rest of the characters from string 1 |
01:29 | Now we will see strncmp function, the syntax for this is strncmp (char str1, char str2 and int n) |
01:43 | It will compare first n characters of string 2 with string 1 |
01:49 | eg. int strncmp(char ice, char icecream, int 2); |
01:56 | The output will be 0 |
01:58 | Now we will see how to use the string library functions. |
02:03 | I am going to show you some of the commonly used string functions. |
02:08 | I have already typed the program on the editor, |
02:11 | i will open it |
02:12 | Here we have the string length function |
02:15 | Note that our filename is strlen.c. |
02:20 | In this we will find the length of the string |
02:24 | These are the header files as stdio.h and string.h |
02:29 | This is our main function |
02:32 | Here we have a character variable 'arr', |
02:36 | It stores a value 'Ashwini' |
02:39 | Then we have an integer variable len1
|
02:43 | here we will find the lenght of the string using strlen funtion |
02:49 | the result will be stored in len1 |
02:53 | Then we print the string and the length of the string. |
02:57 | And this is our return statement
|
02:59 | Now let us execute the program |
03:02 | Open the terminal window by pressing |
03:04 | Ctrl, Alt and T keys simultaneously on your keyboard |
03:10 | To compile |
03:11 | Type: "gcc" space "strlen.c" space “-o” space “str1”. |
03:19 | Press Enter |
03:20 | type: ./str1 |
03:23 | Press Enter |
03:24 | The output is displayed as |
03:26 | string = Ashwini, Length = 7 |
03:30 | You can count here. 1,2,3,4,5,6, and 7 |
03:38 | Let us see another string function |
03:41 | Here we have the string copy fuction |
03:43 | Note that our filename is strcpy.c. |
03:49 | In this we will copy the source string into the target string |
03:54 | Here we have Ice in the source string, it will be copied to the target string . |
04:00 | This is our strcpy function |
04:03 | Here we print the source string and the target string |
04:07 | Let us execute and see |
04:09 | Come back to our terminal |
04:11 | To compile type |
04:12 | gcc space strcpy.c space -o space str2 |
04:19 | Press Enter |
04:21 | Type ./str2 |
04:23 | Press Enter
|
04:25 | The output is displayed as |
04:27 | source string = Ice |
04:30 | target string = Ice |
04:32 | Now let us see another string function |
04:35 | Now we will see the string compare function |
04:38 | Note that our filename is strcmp.c |
04:43 | In this we will comapre two strings |
04:47 | Here we have character variables as str1 and str2
' |
04:53 | str 1 stores the value as 'Ice' and str2 stores the value as 'Cream'. |
04:59 | Here we have interger variables as i and j |
05:04 | In this we will compare the string using the strcmp function |
05: 09 | Here we compare str1 ie: 'Ice' with 'Hello' |
05:14 | The result is stored in i |
05:17 | In this we will compare string 2 ie: 'Cream' with 'Cream' |
05:23 | The result is stored in j |
05:25 | Then we print both the results |
05:28 | and this is our return statement |
05:31 | Let us execute the program. |
05:33 | Come back to our terminal. |
05:35 | To compile type |
05:37 | gcc space strcmp.c space -o space str3 |
05:46 | Press Enter |
05:48 | Type ./str3 |
05:51 | The outpur is displayed as 1,0 |
05:55 | Come back to our program |
05:57 | Here we get 1 |
055:59 | and here we get as 0 |
06:02 | Let us move back to our slides |
06:04 | Let us summarize, |
06:06 | In this tutorial we learned, |
06:08 | String library functions |
06:09 | strlen() |
06:11 | strcpy() |
06:13 | strcmp() |
06:15 | strncpy() |
06:17 | and strncmp()
|
06:20 | As an assignemnt, |
06:21 | Write a C Program to concatenate String best and String bus. |
06:25 | Hint: strcat(char str1, char str2); |
06:33 | Also explore the other functions in string library. |
06:37 | Watch the video available at the link shown below http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial |
06:40 | It summarises the Spoken Tutorial project |
06:43 | If you do not have good bandwidth, you can download and watch it. |
06:47 | The Spoken Tutorial Project Team |
06:49 | Conducts workshops using spoken tutorials |
06:52 | Gives certificates to those who pass an online test |
06:56 | For more details, please write to contact [at] spoken hyphen tutorial dot org |
07:04 | Spoken Tutorial Project is a part of the Talk to a Teacher project |
07:08 | It is supported by the National Mission on Education through ICT, MHRD, Government of India |
07:16 | More information on this Mission is available at: http://spoken-tutorial.org\NMEICT-Intro |
07:21 | This is Ashwini Patil from IIT Bombay. |
07:24 | Thank you for joining. |