1.

What do you know about string function? Explain three-string functions with suitable examples.OrWhat is a string? Explain two string functions of your choice.

Answer»

String Functions. String functions are those functions which  handle string data. ‘C’ language uses a large set of useful string handling library functions. Three string functions are:

1. STRCPY( ): This function copies the contents of one string into another. The base addresses of the source and target strings should be supplied to this function.
Example:

void main()
{
char src[ ] = “Rajeev”;
char tgt[20];
strcpy (tgt, src);
printf (“Source string = %s”, src);
printf (“Target string = %s”, tgt);
}
Output:
Source string = Rajeev
Target string = Rajeev

2. STRLWR(): This function converts upper case (A to Z) string to all lower case (a to z).
Example:

void main()
{
char STR[ ] = “RAJEEV”;
printf (“Upper case = %s”, STR);
strlwr(STR);
printf(“lower case = %s”, STR);
}
Output:
Upper case = RAJEEV
Lower case = rajeev

3. STRUPR( ): This function converts lower case (a to z) string to upper case (A to Z) string:
Example:

void main()
{
char str[ ] = “rajeev”;
prinft (“lower case = %S”, str);
strupr (str);
printf (“upper case = %S”, str);
}

Output:

Lower case = rajeev

Upper case = RAJEEV



Discussion

No Comment Found