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

Answer Posted / dinesh

#include<stdio.h>
#include<conio.h>
void main()
{
char name1[20],name[20];
int i,j,c=0;
clrscr();
printf("enter two strings");
scanf("%s%s",name1,name);
for(i=0,j=0;name1[i]!='\0'||name[j]!='\0';i++,j++)
{
if(name1[i]!=name[j])
{
c++;
}
}
if(c==0)
printf("equal strings");
else
printf("not equal strings");
}

Is This Answer Correct ?    10 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does p mean in physics?

827


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

1034


why we wont use '&' sing in aceesing the string using scanf

2116


How can I recover the file name given an open stream or file descriptor?

867


the statement while(i) puts the entire logic in loop. this loop is called a) indefinite loop b) definite loop c) loop syntax wrong d) none of the above

824


Why calloc is better than malloc?

818


What are types of preprocessor in c?

839


What is identifiers in c with examples?

917


What is c standard library?

945


Is using exit() the same as using return?

960


how to build a exercise findig min number of e heap with list imlemented?

1871


Write the test cases for checking a variable having value in range -10.0 to +10.0?

2113


What is c value paradox explain?

821


Which operators cannot be overloaded a) Sizeof b) .* c) :: d) all of the above

937


Can you add pointers together? Why would you?

911