Top Banner
IMPLEMENTATION OF STRING FUNCTIONS
30

Implementation Of String Functions In C

Jan 24, 2018

Download

Education

Fazila Sadia
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Implementation Of String Functions In C

IMPLEMENTATION OF STRING FUNCTIONS

Page 2: Implementation Of String Functions In C

Hello!

I Am Fazila SadiaRoll No. : BM -014

Page 3: Implementation Of String Functions In C

What Are Strings

Page 4: Implementation Of String Functions In C

“Strings are actually array of

characters terminated by a null

character.Each character occupies one

byte of memory.

Page 5: Implementation Of String Functions In C

String Functions

The prototypes of string functions

can be found in string.h file.The

following is a list of functions found

within the <string.h> header file:

Page 6: Implementation Of String Functions In C

strlen( )

name_variable=strlen(string_name);

Function strlen( ) returns value of type integer

Synatax Of strlen( ) :

Page 7: Implementation Of String Functions In C

Example

Page 8: Implementation Of String Functions In C

Without Using Built In Function

Page 9: Implementation Of String Functions In C

String Concatenation

String concatenation is the operation of

joining character strings end-to-end. For

example, the concatenation of "snow" and

"ball" is "snowball. For two sets of strings S1

and S2, the concatenation S1S2 consists of

all strings of the form vw where v is a string

from S1 and w is a string from S2 .

Page 10: Implementation Of String Functions In C
Page 11: Implementation Of String Functions In C
Page 12: Implementation Of String Functions In C
Page 13: Implementation Of String Functions In C

strcpy( )

Syntax Of strcpy

strcpy(dest,source);

Here, source and destination are

both the name of the string. This

statement, copies the content of

string source to the content of

string destination.

Page 14: Implementation Of String Functions In C

Example

Page 15: Implementation Of String Functions In C
Page 16: Implementation Of String Functions In C

If destination string length is less than source string, entire

source string value won’t be copied into destination string.

For example, consider destination string length is 20 and

source string length is 30.

If you want to copy 25 characters from source string using

strncpy( ) function, only 20 characters from source string

will be copied into destination string and remaining 5

characters won’t be copied and will be truncated.

strncpy( )

strncpy(dest,source,size of)

Syntax Of strcpy( ):

Page 17: Implementation Of String Functions In C
Page 18: Implementation Of String Functions In C

Syntax Of strcmp( )

int strcmp (str_1,str_2);

strcmp is case sensitive, i.e "a" and "A" are

treated as different characters

Page 19: Implementation Of String Functions In C
Page 20: Implementation Of String Functions In C
Page 21: Implementation Of String Functions In C

strncmp( )

Syntax Of strncmp( )

int strncmp(dest,source,size_t);

The strncmp function returns a negative, zero, or

positive integer depending on whether the first n

characters of the object pointed to by s1 are less

than, equal to, or greater than the first n characters of

the object pointed to by s2.

The strncmp function will stop comparing if a null

character is encountered in either s1 or s2

Page 22: Implementation Of String Functions In C
Page 23: Implementation Of String Functions In C

strcmpi( )Syntax Of strcmpi

This function is not case i.e "a" and "A"

are considered same characters.The

strncmpi function returns a negative value

if string1<string2, zero if both are equal, or

positive integer if string1 > string2 .

int strcmpi(dest,source,size_t);

Page 24: Implementation Of String Functions In C
Page 25: Implementation Of String Functions In C

strlwr( )Syntax : strlwr(string_name);

Page 26: Implementation Of String Functions In C
Page 27: Implementation Of String Functions In C

strupr( )

Page 28: Implementation Of String Functions In C
Page 29: Implementation Of String Functions In C

strrev( )

Syntax : strrev(string_name);

Page 30: Implementation Of String Functions In C

Thanks!

Any questions?