Please have a glance. It has to find if the first string suffix of second one.
e.g. 1st world
2nd hello word
hey-you done it! it is a suffix and so on
Code:
#include <stdio.h>
int strlength(char *string)
{
int i=0;
while (string[i]) i++;
return i;
}
int issuffix(char * string1, char * string2)
{
int i,e=0, rest;
rest= strlength(string1)-strlength(string2);
if (strlength(string1) > strlength(string2))
return 0;
for (i=rest; string1[i]; i++)
for (e=0; string2[i]; e++)
{
if (string1[i] != string2[e])
return 0;
}
return 1;
}
main()
{
char stringA[1024], stringB[1024];
int n;
printf("string1: ");
scanf("%c[^\n]", stringA);
printf("string2: ");
scanf("%c[^\n]", stringB);
n=issuffix(stringA,stringB);
if (n)
printf(" \"%s\" is a suffix of %s\n",stringA, stringB);
else
printf(" \"%s\" is NOT a suffix of %s\n",stringA, stringB);
}