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

Stimulate calculator using Switch-case-default statement for two numbers

2734


Explain about block scope in c?

883


Is return a keyword in c?

863


if (i = 0)printf ("True"); elseprintf("False"); Under what conditions will the above print out the string "True" a) Never b) Always c) When the value of i is 0 d) all of the above

957


What are the __date__ and __time__ preprocessor commands?

816


How was c created?

833


What are the complete rules for header file searching?

884


Is a house a shell structure?

939


What does sizeof int return?

863


What is quick sort in c?

853


What is difference between structure and union in c programming?

814


Describe dynamic data structure in c programming language?

850


Explain null pointer.

843


 write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare.  You will then tabulate this information in another file.

1989


how to find binary of number?

3977