fork download
  1. #include <stdio.h>
  2.  
  3. int compVersions ( const char * version1, const char * version2 ) {
  4. unsigned major1 = 0, minor1 = 0, bugfix1 = 0;
  5. unsigned major2 = 0, minor2 = 0, bugfix2 = 0;
  6. sscanf(version1, "%u.%u.%u", &major1, &minor1, &bugfix1);
  7. sscanf(version2, "%u.%u.%u", &major2, &minor2, &bugfix2);
  8. if (major1 < major2) return -1;
  9. if (major1 > major2) return 1;
  10. if (minor1 < minor2) return -1;
  11. if (minor1 > minor2) return 1;
  12. if (bugfix1 < bugfix2) return -1;
  13. if (bugfix1 > bugfix2) return 1;
  14. return 0;
  15. }
  16.  
  17.  
  18. int main ( ) {
  19. int res = compVersions("4.3.2", "4.3.0");
  20. printf("%d", res);
  21. }
Success #stdin #stdout 0s 5280KB
stdin
Standard input is empty
stdout
1