Skip to content

Instantly share code, notes, and snippets.

@mancap314
Last active April 23, 2023 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mancap314/834caf11130e154e58b7527280e9fc68 to your computer and use it in GitHub Desktop.
Save mancap314/834caf11130e154e58b7527280e9fc68 to your computer and use it in GitHub Desktop.
find out if a string ends with a given suffix in C
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
bool endswith(char* str, char* suffix) {
size_t str_length = strlen(str);
size_t suffix_length = strlen(suffix);
if (str_length < suffix_length) return false;
return strncmp(str + str_length - suffix_length, suffix, suffix_length)) == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment