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 is the use of ?

609


When is a “switch” statement preferable over an “if” statement?

636


What are enums in c?

649


Is it cc or c in a letter?

553


What is the difference between array and pointer in c?

566






What does it mean when a pointer is used in an if statement?

592


What is scanf_s in c?

621


What is the difference between test design and test case design?

1558


How do we make a global variable accessible across files? Explain the extern keyword?

1407


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

719


Describe explain how arrays can be passed to a user defined function

593


What is c language and why we use it?

606


How can I insert or delete a line (or record) in the middle of a file?

563


How to declare pointer variables?

675


What are the 3 types of structures?

558