Write a program to compare two strings without using the
strcmp() function
Answer Posted / abhi
#include<stdio.h>
#include<conio.h>
main()
{
char *s1;
char *s2;
int flag=0;
s1=(char *)malloc(10);
s2=(char *)malloc(10);
scanf("%s",s1);
scanf("%s",s2);
while((*s1!='\0')||(*s2!='\0'))
{
if(*s1!=*s2)
flag=1;
else
{
s1++;
s2++;
}
if(flag)
{
if(*s1<*s2)
flag=-1;
break;
}}
if(*s1=='\0'&&*s2!='\0')
flag=-1;
else if(*s1!='\0'&&*s2=='\0')
flag=1;
else
{}
printf("%d",flag);
getch();
}
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
Explain how do you search data in a data file using random access method?
Explain what is wrong with this program statement?
Create a registration form application by taking the details like username, address, phone number, email with password and confirm password (should be same as password).Ensure that the password is of 8 characters with only numbers and alphabets. Take such details for 3 users and display the details. While taking input password must appear as “****”.
What is the return type of sizeof?
What is double pointer?
What are header files in c programming?
List the difference between a 'copy constructor' and a 'assignment operator' in C?
List some applications of c programming language?
What is the purpose of ftell?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record
What are the 32 keywords in c?
What are the advantages of c language?
How do you define structure?
general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only
What is a shell structure examples?