Last active
April 23, 2023 16:17
-
-
Save mancap314/834caf11130e154e58b7527280e9fc68 to your computer and use it in GitHub Desktop.
find out if a string ends with a given suffix in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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