Thanks for your swift reply. I considered the following copy/conversion from 'unsigned int' array to 'char' array but was hoping for fewer steps. However, it's of small consequence.
Thanks again. Jerry. ----- Original Message ----- From: P JH To: [email protected] Sent: Thursday, August 12, 2010 3:26 PM Subject: Re: [c-prog] Question about 'sscanf' conversion On Thu, Aug 12, 2010 at 8:15 PM, <[email protected]> wrote: > Greetings. Is there any way to accomplish the following using 'unsigned char' instead of 'unsigned int'? In short, no. > unsigned int addr[6]; > > (void) sscanf("01:23:45:67:89:AB", "02X:02X:02X:02X:02X:02X", &addr[5], &addr[4], &addr[3], &addr[2], &addr[1], &addr[0]); > > Since the address represented by the string is really 6 bytes I was hoping to convert directly. However, with my current format string sscanf expects the target locations to be unsigned int's. Using unsigned char's for the array expectedly results in a memory error. I could do it manually but if it can be accomplished with an existing function I'd rather use that. > > I see a solution here www.codeproject.com/KB/cpp/MACAddressUtility.aspx[1] which suggests to me sscanf will not suit my purposes. Production code from work parsing the dhcpd leases file: typedef struct ip_user { [...] unsigned char mac[6]; [...] }; [...] int a,b,c,d,e,f,i,j,k,l,ip,indx; [...] } else if( sscanf(buffer," hardware ethernet %x:%x:%x:%x:%x:%x",&a,&b,&c,&d,&e,&f) == 6 ){ user->tmac[0] = a; user->tmac[1] = b; user->tmac[2] = c; user->tmac[3] = d; user->tmac[4] = e; user->tmac[5] = f; -- PJH [Non-text portions of this message have been removed]
