본문 바로가기
C 언어

C 언어 endswith 함수 구현

by treeCoder 2021. 10. 22.

C언어 endswith function 구현

https://stackoverflow.com/questions/5297248/how-to-compare-last-n-characters-of-a-string-to-another-string-in-c

How to Compare Last n Characters of A String to Another String in C

Imagine that I have two strings, one of them is a url like "/sdcard/test.avi" and the other one is"/sdcard/test.mkv". I want to write an if statement that looks whether the last four characters of ...

stackoverflow.com



int endswith(const char* withwhat, const char* what)
{
    int l1 = strlen(withwhat);
    int l2 = strlen(what);
    if (l1 > l2)
        return 0;

    return strcmp(withwhat, what + (l2 - l1)) == 0;
}

댓글