TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Roy McNeill
from: Paul Edwards
date: 1994-12-06 11:10:52
subject: C and octal

RM> Having completely forgotten about octal numbers (didn't they die
 RM> out with the four-toed sloth??) this one caught me short. I'm
 RM> reading a fixed format string that contains 24hr times, and the
 RM> times with leading zeroes stuff up:

 RM>  char *s = "1245 2330 0400";
 RM>  int l,m,n;

 RM>  /* c version */
 RM>  sscanf(s, "%i %i %i", &l,&m,&n);
 
I've never used %i before, I always use %d, and I was pretty sure
%d always treated the things as decimal.  However, I was under the
impression that %i was the same as %d.  So, resorting to the ISO
standard (did you know you can buy this for about $70, and it is
an EXCELLENT reference, a must for every C programmer), it says:

d Matches an optionally signed decimal integer, whose format is
the same as expected for the subject sequence of the strtol
function with the value 10 for the base argument.  The corresponding
argument shall be a pointer to an integer.

i Matches an optionally signed integer, whose format is the same as
expected for the subject sequence of the strtol function with the 
value 0 for the base argument.  The corresponding argument shall
be a pointer to integer.

So there's your problem.  Use d instead of i and she'll be hunky
dory.  BTW, my ISO C standard is no longer in the other room.
BFN.  Paul.
@EOT:

--- Mksmsg
* Origin: none (3:711/934.9)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.