Can someone explain why this example works:
bool SomeFunction(const char * ipIpAddress, int &opOct1, int &opOct2,
int &opOct3, int &opOct4)
{
int b1, b2, b3, b4;
unsigned char c;
if (sscanf(ipIpAddress, "%3i.%3i.%3i.%3i%c", &b1, &b2, &b3, &b4,
&c) != 4)
{
return false;
}
if ((b1  b2  b3  b4) > 255)
{
return false;
}
if (strspn(ipIpAddress, "0123456789.") < strlen(ipIpAddress))
{
return false;
}
opOct1 = b1;
opOct2 = b2;
opOct3 = b3;
opOct4 = b4;
return true;
}
but this one does not? (Segmentation Fault)
bool SomeFunction(const char * ipIpAddress, int &opOct1, int &opOct2,
int &opOct3, int &opOct4)
{
unsigned char c;
if (sscanf(ipIpAddress, "%3i.%3i.%3i.%3i%c", opOct1, opOct2,
opOct3, opOct4, &c) != 4)
{
return false;
}
if ((b1  b2  b3  b4) > 255)
{
return false;
}
if (strspn(ipIpAddress, "0123456789.") < strlen(ipIpAddress))
{
return false;
}
return true;
}
In each case, I am passing references to int's to the sscanf
function.
Thanks,
AJ
