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 -> in c?
What is a volatile keyword in c?
In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
What are the disadvantages of a shell structure?
How can I delete a file?
.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }
What is data type long in c?
What are dangling pointers in c?
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
How can you invoke another program from within a C program?
Program will then find the largest of three numbers using nested if-else statements. User is prompted to enter three numbers. Program will find the largest number and display it on the screen. All three numbers entered by the user are also displayed. If user enters 21, 33, and 5, the output should be as follows: You entered: 21, 33 and 5. The largest number is 33.
write a program to concatenation the string using switch case?
what is the height of tree if leaf node is at level 3. please explain
How old is c programming language?