#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[] = {
{ "a141.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+CgppbnQgY29tcFZlcnNpb25zICggY29uc3QgY2hhciAqIHZlcnNpb24xLCBjb25zdCBjaGFyICogdmVyc2lvbjIgKSB7Cgl1bnNpZ25lZCBtYWpvcjEgPSAwLCBtaW5vcjEgPSAwLCBidWdmaXgxID0gMDsKCXVuc2lnbmVkIG1ham9yMiA9IDAsIG1pbm9yMiA9IDAsIGJ1Z2ZpeDIgPSAwOwoJc3NjYW5mKHZlcnNpb24xLCAiJXUuJXUuJXUiLCAmbWFqb3IxLCAmbWlub3IxLCAmYnVnZml4MSk7Cglzc2NhbmYodmVyc2lvbjIsICIldS4ldS4ldSIsICZtYWpvcjIsICZtaW5vcjIsICZidWdmaXgyKTsKCWlmIChtYWpvcjEgPCBtYWpvcjIpIHJldHVybiAtMTsKCWlmIChtYWpvcjEgPiBtYWpvcjIpIHJldHVybiAxOwoJaWYgKG1pbm9yMSA8IG1pbm9yMikgcmV0dXJ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