Write a program to compare two strings without using the
strcmp() function

Answer Posted / raghu

#include<stdio.h>
#include<conio.h>
void main()
{
char a[100],b[100];
int i,c;
clrscr();
printf("enter first string");
scanf("%s",&a);
printf("enter second string");
scanf("%s",&b);
for(i=0;a[i]!='\0'&&b[i]!='\0';i++)
{
if(a[i]!=b[i])
{
c=1;
}
}
if(c==1)
{
printf("the strings do not match!");
}
else
{
printf("the strings match!");
}
getch();
}

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are the standard predefined macros?

655


What is the use of putchar function?

654


main() { struct s1 { char *str; struct s1 *ptr; }; static struct s1 arr[] = { {"Hyderabad",arr+1}, {"Bangalore",arr+2}, {"Delhi",arr} }; struct s1 *p[3]; int i; < BR> for(i=0;i<=2;i++) p[i] = arr[i].ptr; printf("%s ",(*p)->str); printf("%s ",(++*p)->str); printf("%s ",((*p)++)->str); }

923


What is property type c?

607


What does volatile do?

569






HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2273


What is an operator?

659


Why is void main used?

624


count = 0; for (i = 1;i < = 10; i++);count = count + i; Value of count after execution of the above statements will be a) 0 b) 11 c) 55 d) array

679


Differentiate between full, complete & perfect binary trees.

675


What is the difference between call by value and call by reference in c?

621


to find the closest pair

1825


What is the newline escape sequence?

591


using only #include and #include Write a program in C that will read an input from the user and print it back to the user if it is a palindrome. The string ends when it encounters a whitespace. The input string is at most 30 characters. Assume the string has no spaces and distinguish between and lowercase. So madam is a palindrome, but MadAm is not a palindrome. Use scanf and %s to read the string. Sample Test: Enter a string: madam madam is a palindrome. Enter a string: 09023 09023 is not a palindrome.

1316


How can a program be made to print the name of a source file where an error occurs?

734