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


Please Help Members By Posting Answers For Below Questions

What is the -> in c?

573


What is a volatile keyword in c?

632


In c programming write a program that will print 10 multiples of 3 except 15,18,21 using looping

972


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

647


What are the disadvantages of a shell structure?

682






How can I delete a file?

621


.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; }

1984


What is data type long in c?

617


What are dangling pointers in c?

633


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

1591


How can you invoke another program from within a C program?

609


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.

1008


write a program to concatenation the string using switch case?

1551


what is the height of tree if leaf node is at level 3. please explain

1591


How old is c programming language?

569