/** * 将每个版本号由字符串转换成数字进行比较 * * 比较版本号 * @param version1 string字符串 * @param version2 string字符串 * @return int整型 */ int compare(char* version1, char* version2 ) { int Index1=0, Index2=0; int Val1=0,Val2=0; while(version1[Index1]!='\0'||version2[Index2]!='\0'){ Val1=0; Val2=0; while(version1[Index1]!='.'&& version1[Index1]!='\0'){ Val1=Val1*10+version1[Index1]-'0'; Index1++; } while(version2[Index2]!='.'&& version2[Index2]!='\0'){ Val2=Val2*10+version2[Index2]-'0'; Index2++; } if(Val1>Val2) return 1; else if(Val2>Val1) return -1; if(version1[Index1]!='\0') Index1++; if(version2[Index2]!='\0') Index2++; } return 0; }