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;
}
'C 언어' 카테고리의 다른 글
| C 언어 substring 함수 구현 방법 (1) | 2021.11.23 |
|---|---|
| C언어 개인 프로젝트 (매크로 함수 이용) (0) | 2021.10.26 |
| C언어 fscanf로 파일에서 단어 일어들이기 (0) | 2021.10.14 |
| C언어로 만든 연결 리스트(Linked List) (1) | 2021.09.19 |
| C언어로 문자열 Split 하기 (3) | 2021.09.19 |
댓글