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
What is storage class?
what is event driven software and what is procedural driven software?
How do you print an address?
What are the types of type specifiers?
Why are algorithms important in c program?
what is the height of tree if leaf node is at level 3. please explain
What will the code below print when it is executed? int x = 3, y = 4; if (x = 4) y = 5; else y = 2; printf ("x=%d, y=%d ",x,y);
Why C language is a procedural language?
What is union in c?
What is the use of void pointer and null pointer in c language?
Explain heap and queue.
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
please explain every phase in the "SDLC" in the dotnet.
What are the disadvantages of external storage class?
What is function prototype in c with example?