大伙看看这段程序错在哪里?
#include <iostream>using namespace std;
bool isDigit(char ch)
{
if((ch-'0')>=0 && (ch-'0')<=9)
return true;
return false;
}
unsigned int strToUL(char* ipAddress,char *&remain)
{
unsigned int result=0,value;
while((value=isDigit(*ipAddress)?((*ipAddress)-'0'):-1)>=0)
{
result=result*10+value;
++ipAddress;
}
remain=++ipAddress;
return result;
}
void string_to_ip(char* ipAddress)
{
int i=0;
char *remain=NULL;
for(i=0;i<4;++i)
{
unsigned int value=ipAddress?strToUL(ipAddress,remain):0;
cout<<value<<endl;
ipAddress=remain;
}
}
int main()
{
char ip[]="192.168.1.100";
string_to_ip(ip);
return 0;
}