Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Why passing references to sscanf doesn't work.

Reply
Thread Tools

Why passing references to sscanf doesn't work.

 
 
aj
Guest
Posts: n/a
 
      06-25-2007
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

 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      06-25-2007
aj <(E-Mail Removed)> writes:

> Can someone explain why this example works:
>
> bool SomeFunction(const char * ipIpAddress, int &opOct1, int &opOct2,
> int &opOct3, int &opOct4)


This is C++ code, so comp.lang.c++ would be a better place to ask
about it.
--
"I don't have C&V for that handy, but I've got Dan Pop."
--E. Gibbons
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble with references and sscanf. aj C++ 4 06-25-2007 08:08 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
sscanf not working , why? baumann@pan C Programming 10 06-03-2005 01:45 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM



Advertisments