First off why are you using the C-string functions in the first place? Why not just use C++ strings and then directly compare the strings?
Second I can't reproduce your results because the program fails to compile on my system because you forgot to #include a required include file.
Third after fixing the above issue I get the following output:
Code:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int main()
{
int ret = strcmp("1 222 111", "1 222 11");
cout << "Result: " << ret << "\n";
ret = strncmp("1 222 111", "1 222 11", 9);
cout << "Result: " << ret << "\n";
std::cout << "Are the strings equal: " << std::boolalpha << ("1 222 111" == "1 222 11") << std::endl;
std::cout << "Are the strings equal: " << std::boolalpha << ("1 222 111" == "1 222 111") << std::endl;
return 0;
}
The above produces the following on my system:
Result: 1
Result: 49
Are the strings equal: false
Are the strings equal: true