Write a program to compare two strings without using the
strcmp() function
Answer Posted / ria varughese
#include <stdio.h>
#include <string.h>
void 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);
stringcmp(str1,str2);
return 0;
}
void stringcmp(char *s1, char *s2)
{
int i,j;
for(i=0;s1[i]!='\0';i++)
{
for(j=0;s2[j]!='\0';j++)
{
if(s1[i] == s2[j])
continue;
}
}
if (i==j)
{
printf("String s1:%s and s2:%s are EQUAL\n",s1,s2);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",s1,s2);
}
| Is This Answer Correct ? | 84 Yes | 89 No |
Post New Answer View All Answers
Where are the auto variables stored?
What extern c means?
How can you read a directory in a C program?
What are the scope of static variables?
Why does everyone say not to use scanf? What should I use instead?
Program to find the sum of digits of a given number until the sum becomes a single digit. (e.g. 12345=>1+2+3+4+5=15=>1+5=6)
What do you mean by dynamic memory allocation in c? What functions are used?
What is the difference between char array and char pointer?
How is a macro different from a function?
Explain the process of converting a Tree into a Binary Tree.
With the help of using classes, write a program to add two numbers.
What are c identifiers?
What is quick sort in c?
How many types of arrays are there in c?
What is the difference between single charater constant and string constant?