title: printf changing its value after it should have already been printed
body: <p>So I have this code here, that (for now) just turns a base1 number in to a base 10 number</p>
  
  <pre><code>/**
   * This function is supposed to convert 'number' from base1 to a number in base2.
   * It isn't fully implemented yet, and I've only converted base1 to a base 10 number.
   */
  void base1_base2(int base1, int base2, int number) {
  
      int num, place = 0;
      int rem = number;
      int i;
      for (i = 0; i &lt; num_digits(number); i++) {
  
          int mod = rem % 10;
          rem = floor(rem / 10);
  
          int powerResult = pow(base1, place++);
          num = num + mod * powerResult;  
      }
  
      int base10_num = num;
  
      printf("The number %i(base%i) in base 10 is: %i\n", number, base1, base10_num);
  }
  </code></pre>
  
  <p>And this calculates the correct base10 number, i.e. the function call 
  base1_convert(2, 5, 100) would return 4, as expected:</p>
  
  <p><code>The number 100(base2) in base 10 is: 4</code></p>
  
  <p>The problem arises when I add this code directly beneath the last printf in that function: </p>
  
  <pre><code>int base2_num = 0;
  printf("The number %i(base%i) is: %d\n", number, base1, base2_num);
  </code></pre>
  
  <p>If the above code is added, it completely changes the result of the first printf, making it return:</p>
  
  <pre><code>The number 100(base2) in base 10 is: 4196784.
  The number 100(base2) is: 0
  </code></pre>
  
  <p>I can not for the life of me figure out why this is happening. I'm guessing it has to do with some pointers, but I haven't really used any, and I have no idea why adding a seemingly independent variable <code>int base2_num = 0;</code> would change all of that.</p>
  
  <p>Here is the complete modified code after the above lines are added.</p>
  
  <pre><code>void base1_base2(int base1, int base2, int number) {
  
      int num, place = 0;
      int rem = number;
      int i;
      for (i = 0; i &lt; num_digits(number); i++) {
  
          int mod = rem % 10;
          rem = floor(rem / 10);
  
          int powerResult = pow(base1, place++);
          num = num + mod * powerResult;  
      }
  
      int base10_num = num;
  
      printf("The number %i(base%i) in base 10 is: %i\n", number, base1, base10_num);
  
      int base2_num = 0;
      printf("The number %i(base%i) is: %d\n", number, base1, base2_num);
  
      return;
  } 
  </code></pre>
  
  <p>Edit: And here is the only other function I used, num_digits. It returns the number of digits in an integer.</p>
  
  <pre><code>int num_digits(int integer) {
  
      char int_string[100];
      int str_length;
      sprintf(int_string, "%i", integer);
      str_length = strlen(int_string);
  
      return str_length;
  }
  </code></pre>
  
  <p>And here is where I call the function:</p>
  
  <pre><code>int main() {
      printf("Hello World\n");
      base1_base2(2, 5, 100);
  
      return 0;
  }
  </code></pre>