having some difficulty with some code around strncmp in C just wondering if there is someone that ran into the same problem has me
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int endsWith(char* longStr, char* shortStr);
int main()
{
char* longString = "Grant is The man";
char* shortString = "man";
endsWith(longString,shortString);
printf("%s\n",shortString);
}
int endsWith(char longStr, char shortStr)
{
int offset;
for (offset = 0 ; offset < strlen(shortStr) - strlen(longStr) ; offset ++)
if (strncmp( longStr , shortStr + offset , strlen(longStr)) == 0)
return 1;
return -1;
}
the return should be man and if i inserted is the nothing should be returned or 0.
You have several problems:
strncmp()
,strcmp()
will work.1
or0
, not1
or-1
.