Write a program to compare two strings without using the
strcmp() function
Answer Posted / vikas patel
/*A program to compare of string */
#include<stdio.h>
#include<conio.h>
str_len1(char *s);
str_len2(char *p);
void main()
{
char arr1[20];
char arr2[20];
int len1,len2;
clrscr();
printf("\nEnter the frist string -> ");
scanf("%s",arr1);
printf("\nEnter the second string -> ");
scanf("%s",arr2);
len1 = str_len1(arr1);
len2 = str_len2(arr2);
if(len1==len2)
{
printf("Both string is equal");
}
else
{
printf("Both string is not equal");
}
getch();
}
str_len1(char *s)
{
int length = 0;
while(*s != '\0')
{
length++;
s++;
}
return(length);
}
str_len2(char *p)
{
int a = 0;
while(*p != '\0')
{
a++;
p++;
}
return(a);
}
| Is This Answer Correct ? | 3 Yes | 13 No |
Post New Answer View All Answers
What is the description for syntax errors?
Explain high-order and low-order bytes.
What are the advantages of using linked list for tree construction?
Is c++ based on c?
What is a program flowchart?
How do I use void main?
Do you know the use of fflush() function?
write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3
What is typedef example?
What is the heap in c?
Explain how do you view the path?
What is the difference between array and pointer in c?
Tell us the use of fflush() function in c language?
What is sizeof in c?
A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none