Presentation is loading. Please wait.

Presentation is loading. Please wait.

STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS.

Similar presentations


Presentation on theme: "STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS."— Presentation transcript:

1 STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS

2 The char Data Type Variables of type char take up typically one byte in memory and are used to store printable and non-printable characters. The ASCII code is used to associate each character with an integer For example the ASCII code associates the character ‘m’ with the integer 109. Internally, C treats character variables as integers.

3 ASCII CHARACTER SET

4 WHAT ARE STRINGS In C strings are represented as array of characters Strings ie character arrays are always terminated by a null character(\0) at the end by default Note \0 is used to identify the end of the string ASCII value of \0 is 0

5 Representation of strings in memory The fig shows how the string “college” is represented in the computers memory

6 Declaring strings

7 Reading string inputs Here the string is read with the help of a loop control character by character. This method is very rarely used The declaration char code[20] ; must be done earlier in the program

8 Reading string inputs Here a single word is read. In case of multiple words separated by spaces only the first word is read. This method is used when we are sure that the inputs will not contain multiple words separated by spaces Note: While scanning the ‘&’ symbol is not used as in other cases

9 Reading string inputs The gets( ) is an inbuilt function available with library. This function can read multiple words which are separated by spaces

10 Printing/displaying the strings

11 PROBLEM 1: Write a program to store the name of a student and then display the same

12

13 PROBLEM 2: Write a program to find the length of the name(without using string function)

14

15 PROBLEM 3: Write a program to check whether two strings are equal (without using string functions)

16

17

18 PROBLEM 4: Write a program to count the number of vowels in a string

19

20 PROBLEM 4: Write a program to count the number of words in a string

21

22 Lot of string handling functions are available in the header file So whenever we want to make use of these inbuilt library functions in our program then we must include the string.h file

23 FUNCTIONS IN STRING.H

24 SOME POPULAR ONES

25 Examples of String Functions Here are some examples of string functions in action: char s1[]="big sky country"; char s2[]="blue moon"; char s3[]="then falls Caesar ";

26 Write a program to compare two strings and to concatenate them if they are unequal

27

28 PROBLEM 5: Write a program to check whether a given string is palindrome or not

29

30

31 PROBLEM 2: Write a program to sort a list of names in ascending order

32

33

34


Download ppt "STRINGS & STRING HANDLING FUNCTIONS STRINGS & STRING HANDLING FUNCTIONS."

Similar presentations


Ads by Google