| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | C and octal |
> The result of this proglet is
> 1245 2330 256
> 1245 2330 256
> because C treats numbers with leading zeroes as base 8 numbers.
> I can see several ways of getting around this, but they all seem
> kludgy. Am I missing something obvious? Is there an elegant way to
> get C or C++ to read 0400 as 400dec instead of 256dec?
#include
#include
#include
int main()
{
char *s = "1245 2330 0400";
int l,m,n;
/* c version */
sscanf(s, "%i %i %i", &l,&m,&n);
printf("%i %i %i\n", l,m,n);
/* c++ version */
istrstream test(s, strlen(s));
test >> dec >> l >> m >> n;
printf("%i %i %i\n", l,m,n);
return 0;
}
I don't know of any way of fixing this with sscanf() - but it may exist.
---
* Origin: Unique Computing, Melbourne, Australia (3:632/348)SEEN-BY: 50/99 54/54 620/243 623/630 624/50 632/103 301 348 386 998 633/371 SEEN-BY: 633/379 634/384 635/301 502 503 541 544 636/100 639/100 711/401 409 SEEN-BY: 711/410 430 510 807 808 809 932 934 942 712/623 713/888 714/906 SEEN-BY: 800/1 @PATH: 632/103 348 635/503 50/99 54/54 711/808 809 934 |
|
| 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™.