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

Answer Posted / bharat prajapati

#include <stdio.h>
#include <string.h>

main()

{

char s1[10],s2[10];
int i,j;
clrscr();

printf("\nEnter first String:");
scanf("%s",s1);

printf("\nEnter second String:");
scanf("%s",s2);

for(i=0;s1[i]!='\0';i++)
{
for(j=0;s2[j]!='\0';j++)
{
if(s1[i] == s2[j])
continue;
}
}
if (i==j)
{
printf("String s1 : %s and s2 : %s are EQUAL \n",s1,s2);
}
else
printf("String s1 : %s and s2 : %s are NOT EQUAL
\n",s1,s2);
getch();

}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is null equal to 0 in sql?

644


What is a union?

608


What are the functions to open and close the file in c language?

589


What does node * mean?

705


What is atoi and atof in c?

612






What is boolean in c?

603


application areas a 'c' a) operating system b) graphics, interpreter, assembler c) program evalution, communication softwares d) all the above

601


Why we use conio h in c?

580


Explain void pointer?

587


What is the difference between array and linked list in c?

595


int i=10; printf("%d %d %d", i, i=20, i);

1006


Which control loop is recommended if you have to execute set of statements for fixed number of times?

805


How do we print only part of a string in c?

579


What are dangling pointers? How are dangling pointers different from memory leaks?

617


I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.

1904