About Me

Hello there! Before talking about qualifications and professional abilities, I would like to introduce myself. I am a Yuvraj Basnet and professional software developer and have been working in this field for 3 long years. I have finished my graduation from The University of Delhi on Computer Science Engineering I considered myself a reasonably experienced programmer with a particular interest in the human side of software development, computers are fascinating machine, but they're mostly reflection of the people using them. In the art of software development, studying code isn't enough; you have to study the people behind the software, too.

All String Functions in C Language (Part II)

All String Functions in C Language (Part II)


All String Functions in C Language


In the previous article we discussed String Functions in C programming Language and now in this article we will discuss rest of the string functions in C programming.

1. strcmpi():
strcmpi() function in C is similar as strcmp() function. But, strcmp( ) function is case sensitive but strcmpi() function is not case sensitive. i.e, "Y" and "y" are treated as same characters. Where as, strcmp() function is treats "Y" and "y" as different characters.

Syntax:

int strcmpi ( const char * strng1, const char * strng2 );

PROGRAM TO ILLUSTRATE strcmpi():

OUTPUT:
0-11

2. strchr():
strchr() function searches the first occurrence of a given character in string and returns pointer to it, if found and if not found returns to NULL.

Syntax:
char *strchr(const char *str, int ch);

PROGRAM TO ILLUSTRATE strchr():

OUTPUT:
We Found your First Occurence of a Given Character
The Final String From 'b' is : ial at tutorial Code

3. strrchr():
strrchr() function returns pointer to the last occurrence of the character in a given string.

Syntax:
char *strrchr(const char *str, int ch);  

PROGRAM TO ILLUSTRATE strrchr():

OUTPUT:
is a test

4. strstr():
strstr() function searches the first occurrence of a given string in main string and returns the pointer if found and if not found returns NULL.

Syntax:
char *strstr(const char *str1, const char *str2); 

PROGRAM TO ILLUSTRATE strstr():

OUTPUT:
is is a test

5. strrstr():
strrstr() function searches the last occurrence of a given string in main string and returns the pointer if found and if not found returns NULL.

Syntax:
char *strrstr(const char *str1, const char *str2);

PROGRAM TO ILLUSTRATE strrstr():

OUTPUT:
string found
Last occurrence of string “test” in “This is a test string for testing” is “testing”

6. strdup():
strdup() function is used in C to duplicates the given string. 

Syntax:
char *strdup(const char *string);

PROGRAM TO ILLUSTRATE strdup():


OUTPUT:
Duplicated string is : Code

7. strlwr():
strlwr() function is used in c programming to converts a given string into lowercase and it is a non standard function which may not available in c language. 

Syntax:
char *strlwr(char *string);

PROGRAM TO ILLUSTRATE strlwr():


OUTPUT:
we learn code

8. strupr():

strupr() function is used in c programming to converts a given string into uppercase and it is a also non standard function which may not available in c language.

Syntax:

char *strupr(char *string); 

PROGRAM TO ILLUSTRATE strupr():


OUTPUT:

WE LEARN CODE 

9. strrev():

strupr() function is used in c programming to reverse a given string and it is a also non standard function which may not available in c language.

Syntax:

char *strrev(char *string);

PROGRAM TO ILLUSTRATE strrev():


OUTPUT:

String before strrev( ) : we learn code
String after strrev( )  : edoc nrael ew

10. strset():
strset() function sets all the characters in a string to given character and it is also non standard function in c language.

Syntax:

char *strset(char *string, int c);

PROGRAM TO ILLUSTRATE strset():

OUTPUT:
Original string is : atnyla
Test string after strset() : $$$$$$
After string set: $$$$$$

11. strnset():
strnset() function sets portion of characters in a string to given character and it is also non standard function in c language.

Snytax:

char *strnset(char *string, int c);

PROGRAM TO ILLUSTRATE strnset():


OUTPUT:

Original string is : Welcome to atnyla
Test string after string n set : ######e to atnyla
After string n set : ######e to atnyla

12. strtok():

strtok() function in C tokenizes/parses the given string using delimiter.

Syntax:

char * strtok ( char * str, const char * delimiters );

PROGRAM TO ILLUSTRATE strtok():


OUTPUT:

String  "Test,atnyla,education,string2:Test:string3" is split into tokens:
Test
atnyla
education
string2
Test
string3



Post a Comment

0 Comments