/* The Following C Program code defines a self made srtcmp function which compares between 2 strings. The user is asked 2 strings, the program compares them & displays the result on the basis of ASCII weightage */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int newstrcmp(char *s1, char *s2)
{
int r=0;
while(*s1!='\0'||*s2!='\0')
{
if(*s1!=*s2)
{
r=(int)(*s1-*s2);
return r;
}
s1++;
s2++;
}
return r;
}
int main()
{
char s1[100], s2[100];
int d;
printf("\nEnter the First String:");
gets(s1);
printf("\nEnter the Second String:");
gets(s2);
d=newstrcmp(s1,s2);
if(d<0)
printf("\nSecond String %s have Bigger ASCII Weightage",s2);
else if(d>0)
printf("\nFirst String %s have Bigger ASCII Weightage",s1);
else
printf("\nBoth Are Equal String!");
getch();
return 0;
}
Screenshot:
0 comments:
Post a Comment