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

Tell me is null always defined as 0(zero)?

667


Is there a way to compare two structure variables?

615


What is FIFO?

668


What is the main difference between calloc () and malloc ()?

568


Do you know pointer in c?

585






a c code by using memory allocation for add ,multiply of sprase matrixes

2297


What are local variables c?

547


What are the ways to a null pointer can use in c programming language?

588


Difference between linking and loading?

686


Explain what are run-time errors?

605


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

910


What are pointers in C? Give an example where to illustrate their significance.

746


What are the differences between new and malloc in C?

608


What is indirection?

646


Write the syntax and purpose of a switch statement in C.

618