0

Hi all,

I'm trying to get an octal number from console and store it in an int variable using scanf. Here is my code.

int n;
	scanf("%i", &n);

	printf("\nEntered number in dec = %d", n);
	printf("\nEntered number in hex = %x", n);
	printf("\nEntered number in oct = %o", n);

At console I enter 0238284, then all the printfs outputs 0.
But the same works for hex, ie, if i enter 0xFA31D, then it outputs the decimal, hex and octal values correctly.

Can somebody tell me why it doesn't work in the case of octal. I'm using GCC compiler on 64-bit machine.

Thanks in advance,
Subith

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by subith86
0

> At console I enter 0238284, then all the printfs outputs 0.
When did 8 become a valid octal digit?

0

ooops... what was I doing? thanks for spotting it out... it worked.
I did so many trials, I wonder how all of them had 8 in it :P
anyway thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.