long atol_(const char* nptr){
long total = 0;
char sign = '+';
while( isspace( *nptr ) ){ ++nptr; } // 跳过空格
if( *nptr == '-' || *nptr == '+' ){ sign = *nptr++; } // 检查是否指定符号
while( isdigit( *nptr ) ){
total = 10 * total + ( (*nptr++) - '0' );
}
return (sign == '-') ? -total : total;
}
ULONG inet_addr( IN char *cp ){
char ipBytes[4]={0};
LONG i;
for( i=0; i<4; i++, cp++ ){
ipBytes[i] = (char)atol_( cp );
if( !(cp = strchr( cp, '.' )) ){ break; }
}
return *(ULONG*)ipBytes;
}
自己实现 atol, inet_addr 源代码
最新推荐文章于 2024-02-18 14:12:38 发布