strxfrm() – String Manipulation Function

strxfrm() – String Manipulation Function

How is “strxfrm()” used in C++?

Explanation

strxfrm() manipulation function transforms the characters of “str2” so that it can be used by “strcmp()” and puts the result into “str1”. This function will return the length of the characters in the transformed string.

Syntax:

size_t strxfrm ( char * str1, const char * str2, size_t num );

Example :

#include
#include
int main()
{
char str1[20];
char str2[] = “usanetdir”;
int result = strxfrm(str1, str2, 5);
str2[5] = ”;
printf (“Conversion string: %sn”, str2);
printf (“Length of converted bytes: %in”, result);
return 0;
}

Result :

Conversion string: usane
Length of converted bytes: 9

In the above example, this manipulation is used transform the first 5 characters of “str2”, the number of bytes converted is “9”.





Leave a Reply

Your email address will not be published. Required fields are marked *