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
What does nil mean in c?
What is the explanation for the dangling pointer in c?
if p is a string contained in a string?
How many types of errors are there in c language? Explain
What is a constant and types of constants in c?
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
what is the difference between class and unio?
Can we assign integer value to char in c?
Is main an identifier in c?
What is static volatile in c?
Linked lists -- can you tell me how to check whether a linked list is circular?
What is a stream in c programming?
How can I make sure that my program is the only one accessing a file?
about c language
Write a program to swap two numbers without using the third variable?