Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / fionaa

corrected:

Returns an integral value indicating the relationship
between the strings:
A zero value indicates that both strings are equal.
A value greater than zero indicates that the first character
that does not match has a greater value in str1 than in
str2; And a value less than zero indicates the opposite.

int compare(char str1[], char str2[]) {
int flag = -1;
int i=0;
while(str1[i]!='\0' && str2[i]!='\0'){
if((str1[i]==str2[i])) {flag = 0;}
else if (str1[i]>str2[i]) {
flag=1;
break;
}else if(str1[i]<str2[i]){
flag = -1;
break;
}
i++;
}

if(strlen(str1)==strlen(str2) && flag==0 ){
flag = 0;
}
else if(strlen(str1)>strlen(str2) && flag==0 ){
flag = 1;
}
else if(strlen(str1)<strlen(str2) && flag==0 ){flag = -1;}
return flag;

}

Is This Answer Correct ?    4 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of arrays in c?

1177


Explain the properties of union.

1084


how many key words availabel in c a) 28 b) 31 c) 32

1077


Write the Program to reverse a string using pointers.

1019


What is double pointer?

1000


What is the difference between NULL and NUL?

1290


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

1220


What is self-referential structure in c programming?

1221


Why is c called c?

1023


Declare the structure which contains the following members and write in C list of all students who score more than 75 marks. Roll No, Name, Father Name, Age, City, Marks.

1331


What is the return type of sizeof?

1067


What is the best way to store flag values in a program?

1081


Difference between goto, long jmp() and setjmp()?

1180


What is c basic?

1176


difference between object file and executable file

6724