Write a program to compare two strings without using the
strcmp() function

Answer Posted / waqar nawaz

#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()

{
clrscr();
int c=0;
char a[10];

char b[10];
gets(a);
gets(b);
for(int i=0,j=0;b[i]!='\0'||a[j]!='\0';i++,j++)
{
if(a[i]!=b[j])
{
c++;

}

}
if(c==0)
cout<<"string match";
else
cout<<"string does not match";

getch();
}

Is This Answer Correct ?    104 Yes 51 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What Is The Difference Between Null And Void Pointer?

629


What is the use of putchar function?

642


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15027


What do header files do?

593


Why are algorithms important in c program?

610






Can a local variable be volatile in c?

568


Explain what are the __date__ and __time__ preprocessor commands?

582


Is it better to use malloc() or calloc()?

639


can we implement multi-threads in c.

651


Explain how do you convert strings to numbers in c?

583


which of the following is not a character constant a) 'thank you' b) 'enter values of p, n ,r' c) '23.56E-o3' d) all of the above

1402


What is merge sort in c?

632


When can a far pointer be used?

579


What is the difference between strcpy() and memcpy() function in c programming?

614


Write a program to swap two numbers without using a temporary variable?

599