Working with Strings & Standard Functions 255
stmcpy(str2,strl,n);
printf ("Source String -.‘%S ,s trl);
printf ("nDestination String-:%s",str2);
Q M T U X ;
Enter Source String : wonderful
Enter Destination String: beautiful
Enter Number of Characters to Replace in Destination String: 6
Source String : wonderful
Destination String : wonderful
Explanation In the above program two strings are read from the terminal. Number of characters to
replace in the destination string from source string is also entered. After obtaining these three arguments
the stmcpy () function replaces the destination string with number of characters (argument). The
source string characters are "wonderful" and the destination "beauti fu l" before use of stmcpy ().
After execution, the first six characters of the destination string ( "b e a u ti") are replaced with first six
characters of source string ( "wonder"). The output of the program is as shown above.
stricmpO functions
This function compares the two strings. The characters of the strings may be in lower case or upper
case the function doesn't discriminates between them. i.e. This function compares two strings without
case. If the strings are same it returns to zero otherwise non-zero value.
8.16 Write a Program to compare the two strings using stricmpO function. If strings are
identical display "The Two Strings are Identical" otherwise The Strings are Different
Note: stricmpO function compares two strings character by character and returns 0 if the strings
are identical otherwise non zero value. This function doesn't discriminate between small &
capital letters.
#include <stdio.h>
xnainO
{
char s r [10] , tar [10] ;
int d i f f;
c lrs c r ( );
printf ("Enver S trin g(l): " ) ;
gets(sr);
printf ("Enter Strhtg(2): " );
gets(tar);
diff=stricmp(sr,tar);
if(diff==0)
puts("The Two Strings are Identical/');
else