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

后端 未结 6 1549
野性不改
野性不改 2021-01-02 07:41

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

6条回答
  •  再見小時候
    2021-01-02 08:16

    Just perform if ( strcmp(str1+strlen(str1)-4, str2+strlen(str2)-4) == 0 ) {}.

    Make sure both strings are at least 4 characters long.

提交回复
热议问题