convert a string xxx.xxx.xxx.xxx in a number (CIDR format)
Franco Amato
eurofrank at gmail.com
Mon May 7 14:04:56 PDT 2007
Hi I tried your piece of code but it give to me some problems.
For example if I write
char sz[] =3D "255.2.123";
the if(sscanf(sz,...
give to me error
but if I write
char sz[] =3D "255.2.123.255.255";
the the if(sscanf(sz,...
give to me OK...WHYYYYYYYYY
Is not possible. How can I check the number of fields?
Frank
2007/5/4, H.Vidal, Jr. <hvidal at tesseract-tech.com>:
>
> Franco Amato wrote:
> > Thank to all.
> > To extract every field from the full entiere strind (xxx.xxx.xxx.xxx -
> > every fiels is a single xxx)
> > I used the strtok()...is there an analogue function in c++?
> > Regards
> > Frank
>
> This seems to work for me....
>
> #include <stdio.h>
>
> int main()
> {
> int iA, iB, iC, iD;
>
> char sz[] =3D "255.2.123.4";
>
> if(sscanf(sz,
> "%3d%*[.]%3d%*[.]%3d%*[.]%3d",
> &iA, &iB, &iC, &iD) =3D=3D 4)
> {
> printf("Good\n");
> }
> else
> {
> printf("Bad\n");
> }
> return(0);
> }
>
> You might want to range check the values.
>
> hv
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wx-users-unsubscribe at lists.wxwidgets.org
> For additional commands, e-mail: wx-users-help at lists.wxwidgets.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20070507/81d=
024fe/attachment.htm
More information about the wx-users
mailing list