String handling using libray functions

Illustrate the library functions to handle string operations.

img

Let us have a better understanding of these functions by briefly, discussing them individually.

a. strcpy()

strcpy(s1, “raj”);

will pass the string “raj” to the string variable s1. The statement strcpy(s1, s2)

will assign content of string variable s2 to s1 and the array s1 should have the size to hold the contents of s2 also.


b. Strcat()

This function joins two strings together. The statement Strcat(s1,s2)

Will appened the string s2 to string s1. This is done by removing the null character at the end off s1 and placing s2 from there. The string value at s2 remains unchanged. For example:

n1=”Ram”
n2=”vihar”

Now the statement

Strcat(s1,s2)
Is executed and the result is
N1=Ram Vihar
N2=Vihar
It is also possible to have nesting of strcat() functions. The statement
Strcat(strcat(s1,s2),s3);
Joins all the three strings s1,s2 and s3 together and the result is stored in s1.


c. strlen()

This function counts and returns the number of character in a string. For example in the statement

a=strlen(s);

a is integer variable that receives the length of strings. The counting ends of the first null character.


d. strcmp()

This is used to compare two strings. The statement Strcmp(s1,s2)
Will return 0 if s1 and s2 are equql

Is positive if s1>s2
Is negative if s1<s2


e. strlwr()

This is used to convert string to lowercase. The statement
Strlwr(s1)

Will convert uppercase characters to lowercase.


f. strupr()

This is used to convert string to uppercase. The statement
Strupr(s1)

Will convert lowercase characters to uppercase.


g. strncat()

The general form of this function is :
Strncat(s1,s2,n)

This function is used to append n charcaters of s2 to s1.



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext