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

Explain the difference between ++u and u++?

640


What are the 5 types of inheritance in c ++?

586


what is the diffrenet bettwen HTTP and internet protocol

1393


Why is c used in embedded systems?

614


Why c is faster than c++?

634






What is I ++ in c programming?

628


write a c program to calculate sum of digits till it reduces to a single digit using recursion

2721


What are the disadvantages of external storage class?

592


An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above

658


What is the purpose of 'register' keyword in c language?

629


write a c program to print the next of a particular no without using the arithmetic operator or looping statements?

3190


What does c mean before a date?

592


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 ].

646


How do you search data in a data file using random access method?

835


What is the sizeof () operator?

624