ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Welcome to LinuxQuestions.org, a friendly and active Linux Community.

You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!

Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.

Have problem converting a decimal number to octal
the decimal number is 408.
When converting from 408(decimal) to octal, the value should be 630 (octal)
but instead it gives a value of 40 or 32.

"408" is not a valid octal string, because octal uses only 8 digits: '0' to '7'.
So the digit '8' in "408" is not valid for octal conversion so sscanf() stop the conversion after reading "40".

Also you have some other mistakes in the code, though it would work probably.
To see warnings in addition to erros, compile with

Decimal or octal number, it's kept the sam way. That's displaying that makes the difference...
When you do the sscanf, '408' is taken as an octal number, but it's incorrect (it has '8'), so only two first digits are taken into account.
You get '32' as one of the results, because '32' (decimal) or '40' octal is in octal_number.

LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.