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

Answer Posted / allen

#include<stdio.h>
#include<conio.h>
void stringcmp(char s1[], char s2[]);
void main()
{
char str1[10],str2[10];

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

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

stringcmp(str1,str2);
}

void stringcmp(char *s1, char *s2)
{
int i,j,c=0;
for(i=0,j=0;s1[i]!='\0'||s2[j]!='\0';i++,j++)
{
if(s1[i]!=s2[j])
{
c++;

}

}
if(c==0)
printf("\nstring match");
else
printf("\nstring does not match");
}

Is This Answer Correct ?    12 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does nil mean in c?

924


What is the explanation for the dangling pointer in c?

895


if p is a string contained in a string?

1627


How many types of errors are there in c language? Explain

767


What is a constant and types of constants in c?

846


How to write a code for implementing my own printf() and scanf().... Please hep me in this... I need a guidance... Can you give an coding for c... Please also explain about the header files used other than #include...

5169


what is the difference between class and unio?

2118


Can we assign integer value to char in c?

833


Is main an identifier in c?

856


What is static volatile in c?

763


Linked lists -- can you tell me how to check whether a linked list is circular?

862


What is a stream in c programming?

829


How can I make sure that my program is the only one accessing a file?

956


about c language

1802


Write a program to swap two numbers without using the third variable?

827