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

Recommended Answers

All 2 Replies

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.