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

Answer Posted / ria varughese

#include <stdio.h>
#include <string.h>

void stringcmp(char s1[], char s2[]);

int main()
{

char str1[10],str2[10];

printf("\nEnter first String:");
scanf("%s",str1);

printf("\nEnter second String:");
scanf("%s",str2);

stringcmp(str1,str2);

return 0;
}

void stringcmp(char *s1, char *s2)
{
int i,j;

for(i=0;s1[i]!='\0';i++)
{
for(j=0;s2[j]!='\0';j++)
{
if(s1[i] == s2[j])
continue;
}
}

if (i==j)
{
printf("String s1:%s and s2:%s are EQUAL\n",s1,s2);
}
else
printf("String s1:%s and s2:%s are NOT EQUAL\n",s1,s2);

}

Is This Answer Correct ?    84 Yes 89 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

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


Explain union.

629


What is c system32 taskhostw exe?

580


What is wrong in this statement? scanf(ā€œ%dā€,whatnumber);

717


Explain about the functions strcat() and strcmp()?

595






How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

571


#include #include struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

5178


Explain what are multibyte characters?

617


How can I copy just a portion of a string?

808


How many types of errors are there in c language? Explain

560


Explain what is a pragma?

583


What is a protocol in c?

552


Why is c so important?

589


what are non standard function in c

1423


Can static variables be declared in a header file?

606