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 / sandeep a

// Optimize the above soln...
#include<stdio.h>
int str_cmp(const char *s1, const char *s2)
{
unsigned int i = 0, diff;
while(s1[i]!= '\0' || s2[i] != '\0'){
diff = s1[i] - s2[i];
if(!diff)i++;
else break;
}
return diff;
}
int main(int argc, char *argv[1])
{
printf("chuma %d ", str_cmp("abcd","abcde"));
return 0;
}

Is This Answer Correct ?    35 Yes 49 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

The difference between printf and fprintf is ?

1338


What language is windows 1.0 written?

1131


write a progrmm in c language take user interface generate table using for loop?

2099


If I have a char * variable pointing to the name of a function ..

1227


What type of function is main ()?

1081


What is multidimensional arrays

1172


write a c program to find the largest and 2nd largest numbers from the given n numbers without using arrays

2284


What are compound statements?

1238


What is array of structure in c programming?

1328


How can I read/write structures from/to data files?

1012


What are the parts of c program?

1153


Explain how can I prevent another program from modifying part of a file that I am modifying?

1138


What is the general form of function in c?

1068


if p is a string contained in a string?

1887


Tell me the use of bit field in c language?

1104