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 is the use of ?
When is a “switch” statement preferable over an “if” statement?
What are enums in c?
Is it cc or c in a letter?
What is the difference between array and pointer in c?
What does it mean when a pointer is used in an if statement?
What is scanf_s in c?
What is the difference between test design and test case design?
How do we make a global variable accessible across files? Explain the extern keyword?
Write a code to generate a series where the next element is the sum of last k terms.
Describe explain how arrays can be passed to a user defined function
What is c language and why we use it?
How can I insert or delete a line (or record) in the middle of a file?
How to declare pointer variables?
What are the 3 types of structures?