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 difference between class and structure?
What is the best style for code layout in c?
What are linker error?
What is New modifiers?
What is wrong in this statement? scanf(ā%dā,whatnumber);
disply the following menu 1.Disply 2.Copy 3.Append; as per the menu do the file operations 4.Exit
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
Explain the array representation of a binary tree in C.
When is a void pointer used?
how to build a exercise findig min number of e heap with list imlemented?
Explain how can I make sure that my program is the only one accessing a file?
Is struct oop?
Explain the advantages of using macro in c language?
Why is extern used in c?
How many loops are there in c?