#include <stdio.h>
int compVersions ( const char * version1, const char * version2 ) {
unsigned major1 = 0, minor1 = 0, bugfix1 = 0;
unsigned major2 = 0, minor2 = 0, bugfix2 = 0;
sscanf(version1
, "%u.%u.%u", &major1
, &minor1
, &bugfix1
); sscanf(version2
, "%u.%u.%u", &major2
, &minor2
, &bugfix2
); if (major1 < major2) return -1;
if (major1 > major2) return 1;
if (minor1 < minor2) return -1;
if (minor1 > minor2) return 1;
if (bugfix1 < bugfix2) return -1;
if (bugfix1 > bugfix2) return 1;
return 0;
}
int main ( ) {
struct {
const char * version1;
const char * version2;
} testVersions[] = {
{ "141.1.23", "141.1.22" },
{ "141.1.23", "145.1.22" },
{ "141.2.23", "141.1.23" },
{ "141.1.0", "141.1" }
};
size_t testCount = sizeof(testVersions) / sizeof(testVersions[0]);
for (size_t i = 0; i < testCount; i++) {
int res = compVersions(
testVersions[i].version1, testVersions[i].version2);
testVersions[i].version1,
(res == 0 ? "=" : res == -1 ? "<" : ">"),
testVersions[i].version2);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgY29tcFZlcnNpb25zICggY29uc3QgY2hhciAqIHZlcnNpb24xLCBjb25zdCBjaGFyICogdmVyc2lvbjIgKSB7Cgl1bnNpZ25lZCBtYWpvcjEgPSAwLCBtaW5vcjEgPSAwLCBidWdmaXgxID0gMDsKCXVuc2lnbmVkIG1ham9yMiA9IDAsIG1pbm9yMiA9IDAsIGJ1Z2ZpeDIgPSAwOwoJc3NjYW5mKHZlcnNpb24xLCAiJXUuJXUuJXUiLCAmbWFqb3IxLCAmbWlub3IxLCAmYnVnZml4MSk7Cglzc2NhbmYodmVyc2lvbjIsICIldS4ldS4ldSIsICZtYWpvcjIsICZtaW5vcjIsICZidWdmaXgyKTsKCWlmIChtYWpvcjEgPCBtYWpvcjIpIHJldHVybiAtMTsKCWlmIChtYWpvcjEgPiBtYWpvcjIpIHJldHVybiAxOwoJaWYgKG1pbm9yMSA8IG1pbm9yMikgcmV0dXJu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