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

How can I read in an object file and jump to locations in it?

753


Is there a way to compare two structure variables?

800


How do you determine whether to use a stream function or a low-level function?

873


c language interview questions & answer

1643


c language supports bitwise operations, why a) 'c' language is system oriented b) 'c' language is problem oriented c) 'c' language is middle level language d) all the above

785






Write a code to generate a series where the next element is the sum of last k terms.

940


What does return 1 means in c?

756


What is %d called in c?

911


What is the difference between struct and union in C?

820


What is meant by 'bit masking'?

1073


Write a program to know whether the input number is an armstrong number.

863


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

822


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

830


What does int main () mean?

724


Why void main is used in c?

746