Write a program to compare two strings without using the
strcmp() function

Answer Posted / shashi

#include<stdio.h>
#include<conio.h>

int stringcmp(char s1[], char s2[]);

int main()
{

char str1[10],str2[10];

printf("\nEnter first String:");
scanf("%s",str1);

printf("\nEnter second String:");
scanf("%s",str2);


if (stringcmp(str1,str2))
{
printf("String s1:%s and s2:%s are EQUAL\n",str1,str2);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",str1,str2);
getch();

return 0;
}

int stringcmp(char *s1, char *s2)
{
int flag=0;
char *count;
count=s1;
while(*count++)
{
flag=0;
if(*s1++==*s2++)
{
flag=1;
}
}

return flag;

}

Is This Answer Correct ?    4 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How are Structure passing and returning implemented by the complier?

723


If a variable is a pointer to a structure, then which operator is used to access data members of the structure through the pointer variable?

790


What does the c in ctime mean?

583


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15066


What is the use of a ‘’ character?

595






What is putchar() function?

644


What are the advantage of c language?

562


What is meant by keywords in c?

629


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

598


Is there a built-in function in C that can be used for sorting data?

751


Why c is known as a mother language?

658


Do array subscripts always start with zero?

792


How can I get back to the interactive keyboard if stdin is redirected?

677


Write a program to use switch statement.

671


Why is c so powerful?

695