帮忙改错 八进制转换为十进制
#include <stdio.h>main()
{ char *p,s[6];
int n;
p=&s;
gets(p);
n=*p-'0';
while(++p!='\0') n=n*8+*p-'0';
printf("%d \n",n);
}
#include <stdio.h> int main() { char *p; char s[6]={'\0'}; int n; p=&s[0]; gets(p); //令p="369" n=*p-'0';//n=3 while(*p!='\0') { printf("n=%d p=%c\n",n,*p); n=n*8+*p-'0'; p++; } printf("num=%d \n",n); return 0; } /* 如何调试本程序: 369 n=3 p=3 n=27 p=6 n=222 p=9 num=1785 */