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
Is it possible to have a function as a parameter in another function?
What is the advantage of a random access file?
What will the preprocessor do for a program?
Define VARIABLE?
What is return type in c?
What is a lvalue
There is a practice in coding to keep some code blocks in comment symbols than delete it when debugging. How this affect when debugging?
What is meant by keywords in c?
Who developed c language?
What is a const pointer?
What is the meaning of && in c?
What is substring in c?
Explain how can I avoid the abort, retry, fail messages?
#include main() { enum _tag{ left=10, right, front=100, back}; printf("left is %d, right is %d, front is %d, back is %d",left,right,front,back); }
What is #define size in c?