Hi guys,
Anyone see whats wrong here?
What im trying to do is input two strings say s and t.
Return true if the string s is at the end of string t.
My function just keeps return true.
cheers!
Code:
#include <stdio.h>
#include <string.h>
#define SIZE 1000
int strend( char [], char [] );
int main()
{
char s[SIZE];
char t[SIZE];
printf( "Enter s: " );
fgets( s, SIZE, stdin );
printf( "Enter t: " );
fgets( t, SIZE, stdin );
if ( strend( s, t ) )
printf( "string s occurs at end of string t\n" );
else
printf( "string s does not occur at the end of string t\n" );
return 0;
}
int strend( char s[], char t[] )
{
int i;
int j;
for ( i=strlen(t)-strlen(s); i<strlen(t)-2; ) {
printf( "%d\n", i );
for( j=0; j<strlen(s)-2; ) {
if ( t[i] == s[j] )
{
i++;
j++;
break;
}
else {
return 0;
}
}
}
return 1;
}