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
How #define works?
What is the auto keyword good for?
What are the preprocessor categories?
What are the different types of constants?
What is the hardest programming language?
What are the types of functions in c?
What is the advantage of a random access file?
What is difference between union and structure in c?
Explain how do you generate random numbers in c?
What is a string?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
What are structural members?
Write a program to show the change in position of a cursor using c
What tq means in chat?
What is typedef?