Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- str1 = "141.1.23"
- str2 = "141.1.22"
- strunct version_t {
- int major;
- int minor;
- int build;
- };
- version_t parse_ver(const char* version_str) {
- version_t res;
- // Use strtok_r to split the string, and atoi to convert tokens to ints
- return res;
- }
- #include <assert.h>
- #include <stdlib.h>
- int versionCmp( char *pc1, char *pc2)
- {
- int result = 0;
- /* loop through each level of the version string */
- while (result == 0) {
- /* extract leading version numbers */
- char* tail1;
- char* tail2;
- unsigned long ver1 = strtoul( pc1, &tail1, 10 );
- unsigned long ver2 = strtoul( pc2, &tail2, 10 );
- /* if numbers differ, then set the result */
- if (ver1 < ver2)
- result = -1;
- else if (ver1 > ver2)
- result = +1;
- else {
- /* if numbers are the same, go to next level */
- pc1 = tail1;
- pc2 = tail2;
- /* if we reach the end of both, then they are identical */
- if (*pc1 == '