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 / yathish m yadav

#include<conio.h>
int strcmp(char *,char *);

char a[10],b[10];
void main()
{
int c;
printf("enter the first string\n");
scanf("%s",a);
printf("enter the second string\n");
scanf("%s",b);
c=strcmp(a,b);
switch(c)
{
case 1: printf("first string is larger then second");
break;
case 2: printf("second is greater than first");
break;
case 3: printf("not equal");
break;
case 4: printf("the strings are equal");
break;
}
getch();
}

int strcmp(char *p,char *q)
{
int m,n;
m=strlen(p);
n=strlen(q);
if(m>n){
return (1);}
else if(n>m){
return (2);}
for(i=0;i<m;i++)
{
if(p[i]!=q[i])
return(3);
}
return(4);
}

Is This Answer Correct ?    4 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can you call a function, given its name as a string?

1204


What is pointer to pointer in c language?

1207


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

3211


Is c still used?

1095


What does %p mean?

1152


What is self-referential structure in c programming?

1276


console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above

1219


Can we assign string to char pointer?

1172


How is null defined in c?

1200


What is the stack in c?

1222


Is there a way to compare two structure variables?

1169


the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none

1107


Write a code to generate divisors of an integer?

1103


what are the 10 different models of writing an addition program in C language?

1941


What is far pointer in c?

1387