Given that you are trying to compare char*
pointers instead of actually comparing strings, I must recommend you to read a good C++ book first. You can pick one from The Definitive C++ Book Guide and List
As for comparing last N character of the string, there are many ways of doing this. Here is just one to get you started:
#include <string>
#include <cctype>
#include <algorithm>
#include <iterator>
#include <iostream> // For example output only.
bool ends_with(
const std::string& str, const std::string& with,
bool ignore_case = false
) {
if (str.length() < with.length())
return false;
const auto offset = str.length() - with.length();
return (
ignore_case ?
std::equal(
std::begin(str) + offset, std::end(str), std::begin(with),
[](char a, char b){ return ::toupper(a) == ::toupper(b); }
) :
std::equal(std::begin(str) + offset, std::end(str), std::begin(with))
);
}
int main() {
std::string filename{"myfile.txt"};
if (ends_with(filename, ".txt"))
std::cout << "It is a text file!\n";
if (ends_with(filename, ".TXT"))
std::cerr << "Something is wrong :(\n";
if (ends_with(filename, ".TXT", true))
std::cout << "Yeah, it is really a text file!\n";
}
This is a modified version taken from here. I have found it in 5 seconds using GitHub code search, and there are literally thousands of results for C++, so you might want to check it out, read and try to understand the code, that would help you learn C++.
Hope it helps. Good Luck!