79461865

Date: 2025-02-23 19:51:34
Score: 1.5
Natty:
Report link

If you were to generalize this problem, to say "Does a string str end with a string suffix?" you could do the following:

#include <string.h>

int endswith(char* str, char* suffix) 
{
    // assuming that str and suffix are not NULL
    return strcmp(str + strlen(str) - strlen(suffix), suffix) == 0;
}

It would be trivial to add a check for NULL to the function as well:

#include <string.h>

int endswith(char* str, char* suffix) 
{
    return str && suffix && strcmp(str + strlen(str) - strlen(suffix), suffix) == 0;
}
Reasons:
  • RegEx Blacklisted phrase (1.5): fix?
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (0.5):
Posted by: Rusty