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
How many levels deep can include files be nested?
Why c is a mother language?
Is c is a middle level language?
What are the __date__ and __time__ preprocessor commands?
How can I make sure that my program is the only one accessing a file?
How can I split up a string into whitespace-separated fields?
what is event driven software and what is procedural driven software?
What is anagram in c?
What is far pointer in c?
What is action and transformation in spark?
Why c is procedure oriented?
What are the types of arrays in c?
What is the difference between array and pointer?
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory
What are the advantages and disadvantages of pointers?