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

Why is c so important?

598


How to set file pointer to beginning c?

672


given post order,in order construct the corresponding binary tree

2325


to print the salary of an employee according to follwing calculation: Allowances:HRA-20% of BASIC,DA-45% of BASIC,TA-10%. Deductions:EPF-8% of BASIC,LIC-Rs.200/-Prof.Tax:Rs.200/- create c language program?

1575


What is the advantage of an array over individual variables?

746






What is dynamic memory allocation?

812


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

637


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

629


Should a function contain a return statement if it does not return a value?

601


What do you mean by recursion in c?

630


Explain a file operation in C with an example.

665


What is %d called in c?

763


What is the size of a union variable?

604


Why c is called object oriented language?

592


What is wrong with this program statement? void = 10;

826