II-176 Programming Concepts
String comparison with and without strcmp() function
16. Program on comparison of two strings
void main()
{
char str1[20]={'C','o','m','p','u','t','e','r'},
str2[20]={'C','o','m','p','u','t','e','r'};
clrscr();
if( (strcmp(str1,str2))==0)
printf("Length of the strings are same
");
else
printf("Length of the strings are not same
");
getch();
}
OUTPUT:
Length of the strings are same
17. Program to compare the two strings
void main()
{
char str1[20]={'G','o','d','a','w','a','r','i'},
str2[20]={'S','a','r','a','s','w','a','t','i'};
int diff;
clrscr();
diff=(strcmp(str1,str2));
if(diff==0)
printf(" strings are same
");
else
printf(" strings are not same
");
getch();
}
OUTPUT:
strings are not same
18. Program on stricmp() function
#include <stdio.h>
#include <conio.h>
#include <process.h>
void main()
M08_ITL-ESL4791_02_SE_C08.indd 176 12/22/2012 5:03:31 PM