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

int compare(char str2[], char str1[]) {
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 {flag = -1;}
return flag;
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?

985


What is meant by gets in c?

1103


Explain what is the difference between far and near ?

1047


What are identifiers and keywords in c?

1033


Find MAXIMUM of three distinct integers using a single C statement

1013


Describe wild pointers in c?

1060


Explain what is meant by 'bit masking'?

1120


Does c have function or method?

942


int i[2], j; int *pi;i[0] = 1; i[1] = 5; pi = i; j = *pi + 1 + *(pi + 1)Value of j after execution of the above statements will be a) 7 b) 6 c) 4 d) pointer

990


When should a far pointer be used?

1060


When is a void pointer used?

1192


What is a stream water?

1127


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

2638


What is a global variable in c?

954


How can I rethow can I return a sequence of random numbers which dont repeat at all?

1147