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
Which control loop is recommended if you have to execute set of statements for fixed number of times?
Give me the code of in-order recursive and non-recursive.
What is methods in c?
Why does everyone say not to use gets?
An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode
Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
Differentiate between #include<...> and #include '...'
if a is an integer variable, a=5/2; will return a value a) 2.5 b) 3 c) 2 d) 0
I came across some code that puts a (void) cast before each call to printf. Why?
Explain how do you print an address?
What is the use of a ‘ ’ character?
Difference between malloc() and calloc() function?
Explain what is the use of a semicolon (;) at the end of every program statement?
What is the use of getchar() function?
What are multidimensional arrays?