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

Answer Posted / abhishek

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<conio.h>
void main()
{
clrscr();
char a[100],b[100];
int i,m;
cout<<"enter first string";
gets(a);
cout<<"enter second string";
gets(b);
for(i=0;a[i]!='\0'&&b[i]!='\0';i++)
{
if(a[i]!=b[i])
{
c=1;
}
}
if(c==1)
{cout<<"the strings do not match!";
}
else
{
cout<<"the strings match!";
}
getch();
}

Is This Answer Correct ?    7 Yes 9 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of arrays in c?

629


Differentiate between Macro and ordinary definition.

740


What is the incorrect operator form following list(== , <> , >= , <=) and what is the reason for the answer?

963


What is pointer to pointer in c with example?

558


What is the c value paradox and how is it explained?

587






A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers

659


Do array subscripts always start with zero?

792


What is modifier & how many types of modifiers available in c?

618


How can I remove the leading spaces from a string?

644


How can you increase the size of a statically allocated array?

629


find out largest elemant of diagonalmatrix

1657


What is the sizeof () a pointer?

561


What functions are used for dynamic memory allocation in c language?

615


What is the g value paradox?

656


When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?

818