# include & ltstring.h & gt
/*************************************************************************
Function: A character processing function that converts non-negative decimal integers into octal characters.
Parameter: int num: decimal number; Char *ptr: Save the converted octal string.
Return: ptr (the first address of the array that holds the string)
*************************************************************************/
Char *dec_to_oct (unsigned long integer, char * ptr);
int main(void)
{
//Used for testing
char str[ 12];
int num = 0;
char * p;
Printf ("You can enter several non-negative integers continuously:");
while( 1)
{
scanf("%d ",& ampnum);
if(num & lt; 0)
Break;
p = dec_to_oct(num,str);
//printf("strlen(str)=%d\n ",strlen(p));
printf("Dec:%d = Oct:%s\n ",num,p);
}
Returns 0;
}
Char *dec_to_oct (unsigned long integer number, char *ptr)
{
Unsigned long integer n = num
int I = 0;
int j = 0;
Unsigned length tmp
char ch
while((n/8)! =0){
tmp = n % 8;
ch = tmp+' 0 ';
*(ptr+I)= ch;
n = n/8;
i++;
}
tmp = n % 8;
ch = tmp+' 0 ';
*(ptr+I)= ch;
i++;
*(ptr+I)= ' \ 0 ';
/* Because the most significant bit of oct is at the end of the array and the least significant bit is at the beginning of the array, the character array is inverted */
tmp = I/2;
j = 0;
I-;
while(j & lt; tmp)
{
ch = *(ptr+j);
*(ptr+j)= *(ptr+I);
*(ptr+I)= ch;
I-;
j++;
}
Return ptr
}