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
If you have a pointer-to-char array, str
, then this:
int len = strlen(str);
const char *last_four = &str[len-4];
will give you a pointer to the last four characters of the string. You can then use strcmp()
. Note that you'll need to cope with the case where (len < 4)
, in which case the above won't be valid.