Skip to content

Instantly share code, notes, and snippets.

@bentrevett
Last active February 1, 2017 20:33
Show Gist options
  • Save bentrevett/dbcd32e28952f4857b77c5c6970e9c3c to your computer and use it in GitHub Desktop.
Save bentrevett/dbcd32e28952f4857b77c5c6970e9c3c to your computer and use it in GitHub Desktop.
Returns true if the string t occurs at the end of the string s, and false otherwise.
#include <string.h>
#include <stdbool.h>
bool strend(const char *s, const char *t)
{
size_t slen = strlen(s);
size_t tlen = strlen(t);
if (tlen > slen) return false;
else return !strcmp(s + (slen - tlen), t);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment