Write a program to compare two strings without using the
strcmp() function
Answer Posted / md.ershad.ezaz
int strcompare(char *,char *);
void main()
{
char s1[15],s2[15];
int cmp;
clrscr();
puts("Enter first string");
gets(s1);
puts("Enter second string");
gets(s2);
cmp=strcompare(s1,s2);
if(cmp==0)
puts("strings are equal");
else
puts("strings are not equal");
getch();
}
int strcompare(char *p1,char *p2)
{
while(*p1==*p2)
{
if(*p1=='\0')
return(0);
p1++;
p2++;
}
return(*p1-*p2);
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Linked lists -- can you tell me how to check whether a linked list is circular?
Explain what is a static function?
What is a header file?
What is break in c?
what is a constant pointer in C
List the different types of c tokens?
Explain that why C is procedural?
What are the storage classes in C?
With the help of using classes, write a program to add two numbers.
What is a node in c?
What is dynamic dispatch in c++?
What is a null string in c?
How can you pass an array to a function by value?
What does the error message "DGROUP exceeds 64K" mean?
my project name is adulteration of chille powder.how can i explain it to the hr when he asks me about the project?