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
Explain how do you determine the length of a string value that was stored in a variable?
What is meant by initialization and how we initialize a variable?
write a program in c language to print your bio-data on the screen by using functions.
How macro execution is faster than function ?
Do pointers need to be initialized?
When do we get logical errors?
Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?
Given only putchar (no sprintf, itoa, etc.) write a routine putlong that prints out an unsigned long in decimal. [ I gave the obvious solution of taking % 10 and / 10, which gives us the decimal value in reverse order. This requires an array since we need to print it out in the correct order. The interviewer wasn't too pleased and asked me to give a solution which didn't need the array ].
What is mean by data types in c?
Write a function expand(s1,s2) that expands shorthand notations like a-z in the string s1 into the equivalent complete list abc...xyz in s2 . Allow for letters of either case and digits, and be prepared to handle cases like a-b-c and a-z0-9 and -a-z. z-a:zyx......ba -1-6-:-123456- 1-9-1:123456789987654321 a-R-L:a-R...L a-b-c:abbc
Explain why c is faster than c++?
How to find a missed value, if you want to store 100 values in a 99 sized array?
differentiate built-in functions and user – defined functions.
What are the advantages and disadvantages of a heap?
Why shouldn’t I start variable names with underscores?