exc/k&r/05-pointers-and-arrays/05-04.c

22 lines
505 B
C

#include <stdio.h>
#include <string.h>
int strend(const char *s, const char *t);
/* passes args to strend, prints result */
int main(int argc, char *argv[])
{
if (argc < 3)
return 1;
printf("%s\n", (strend(argv[1], argv[2])) ? "true" : "false");
return 0;
}
/* strend: returns 1 if t == end of s otherwise false */
int strend(const char *s, const char *t)
{
size_t s_len = strlen(s);
size_t t_len = strlen(t);
return (s_len >= t_len) && !strcmp(s + s_len - t_len, t);
}