/* octal.c * converts decimal numbers to octal * * King Chapter 4, Ex. 4. * * By Cory Spitzer * March 7th, 2013 * * 8**5 = 32768 * 8**4 = 4096 * 8**3 = 512 * 8**2 = 64 */ #include #include int main(){ char num_str[8]; char* thing; //char other[]; int number = 0; int number_copy; int o234 = 02322; // is this a way to input octal? int octal_digits[16]; // each digit is 0 to 7 int index; /* addr value ---- ----- 0 - 3 0x00802000 hell 32bits = 4 bytes 4 - 7 0x00802004 o/0.. ... num_str 0x00803008 0x00802000 address of 0th char thing 0x0080300c ......... random crap for now other 0x00803010 ......... ditto number 0x00803014 0x00000000 0 as a 32 bit signed int */ thing = num_str + 1; strcpy(num_str, "hello"); // put 'hello' printf("num_str = '%s'\n", num_str); // prints 'hello' printf("thing = '%s'\n", thing); // prints 'ello' // or char* num_string? I'm not grokking this yet //int oct_number = 0; //int i; printf("Enter an integer between 0 and 32767 - (8^5 - 1)"); //fgets(num_string, 8, stdin); scanf("%i", &number); // put an integer in 0x00803014 number_copy = number; index = 0; while (number > 0){ octal_digits[index] = number % 8; number >>= 3; // same as 'number /= 8'; index++; } printf(" as octal = "); while (index--) printf("%1i", octal_digits[index]); printf("\n"); printf(" check : %o \n", number_copy); printf(" o234 = %d \n", o234); // print as octal //for (i = 0; i < 5; i++) { // //} //oct_number = return 0; }