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
Create a simple code fragment that will swap the values of two variables num1 and num2.
Explain the difference between strcpy() and memcpy() function?
Difference between Function to pointer and pointer to function
When is a void pointer used?
Can a pointer be null?
What is %s and %d in c?
What is c preprocessor mean?
Why is not a pointer null after calling free?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34
How can I discover how many arguments a function was actually called with?
What’s the special use of UNIONS?
Can two or more operators such as and be combined in a single line of program code?
What is maximum size of array in c?
What is identifiers in c with examples?