将八进制数转换为C中的十进制数

Hor*_*nce 1 c octal

#include <stdio.h>
#include <math.h>

void main() {
    long int on, temp;
    int dn = 0, e = 0, digit;
    printf("Enter octal number : ");
    scanf("%ld", &on);
    temp = on;
    while (on != 0) {
        digit = on % 10;
        dn += digit * pow(8, e);
        e++;
        on /= 10;
    }
    printf("octal number = %ld \n", temp);
    printf("Decimal number= %d  \n", dn);

    return 1;
}
Run Code Online (Sandbox Code Playgroud)

你好,美好的一天.我有这个代码将八进制数转换为十进制,但我的问题/问题是如何制作一个将转换八进制十进制数的代码.例:

0.75 8 →___ 10

0.00001 8 →___ 10

在转换中,你必须将每个数字乘以8的平方(8,64,542 ...)

我需要帮助.

小智 6

不要这样做.

将用户的数据读入char*缓冲区.

然后使用strtoul(); 指定基数为8.