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
How are Structure passing and returning implemented by the complier?
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?
What does the c in ctime mean?
Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10
What is the use of a ‘ ’ character?
What is putchar() function?
What are the advantage of c language?
What is meant by keywords in c?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
Is there a built-in function in C that can be used for sorting data?
Why c is known as a mother language?
Do array subscripts always start with zero?
How can I get back to the interactive keyboard if stdin is redirected?
Write a program to use switch statement.
Why is c so powerful?