Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sscanf and octals

Tags:

c

macos

scanf

Why wouldn't it just work?

const char* ip =  "192.168.1.4";
unsigned int ip4[4];
sscanf(ip,"%o.%o.%o.%o",ip4,ip4+1,ip4+2,ip4+3); // doesn't work
sscanf(ip,"%d.%d.%d.%d",ip4,ip4+1,ip4+2,ip4+3); // works

I checked man pages for scanf(3) and it clearly states that %o is perfectly acceptable.

like image 871
bioffe Avatar asked Dec 21 '22 08:12

bioffe


1 Answers

There is no "8" and "9" in octal, so 192 and 168 aren't octal numbers, so sscanf can't parse them as octal numbers.

like image 161
ikegami Avatar answered Dec 24 '22 02:12

ikegami