#include #include Version parseVersion(const char *versionStr) { Version v = {0, 0, 0}; // Initialize with default values // Buffer to check for any extra content char extraContent; // Try to extract three integers and check for non-numeric trailing characters int parsedCount = sscanf(versionStr, "%d.%d.%d%c", &v.major, &v.minor, &v.patch, &extraContent); // If parsed count is not 3, or there is an extra character, mark as invalid if (parsedCount > 3) { v.major = v.minor = v.patch = 0; } return v; } Configuration getLatestConfiguration(Configuration *configs, int count) { Configuration latest = configs[0]; for (int i = 1; i < count; i++) { const Version ¤tVersion = configs[i].version; const Version &latestVersion = latest.version; // Compare the versions stored in the Configuration structs if (currentVersion.major > latestVersion.major || (currentVersion.major == latestVersion.major && currentVersion.minor > latestVersion.minor) || (currentVersion.major == latestVersion.major && currentVersion.minor == latestVersion.minor && currentVersion.patch > latestVersion.patch)) { latest = configs[i]; } } return latest; } bool isVersionNewer(Version oldVersion, Version newVersion) { if (newVersion.major > oldVersion.major || (newVersion.major == oldVersion.major && newVersion.minor > oldVersion.minor) || (newVersion.major == oldVersion.major && newVersion.minor == oldVersion.minor && newVersion.patch > oldVersion.patch)) { return true; } return false; }