title: Extracting Digits from an Integer in C?
body: <pre><code>void print(int num, int digits)
  {
      double mod, divi;
      int mod1, divi1;
      mod = pow(10, digits);
      divi = pow(10, digits-1);
      mod1 = (int)mod;
      divi1 = (int)divi;
  
      if(digits &gt; 0)
      {
          printf("%d\n", ((num%mod1)/divi1));
          digits--;
          print(num, digits);
      }
      else
      {
          return;
      }
  }
  </code></pre>
  
  <p>This function is meant to print the digits from <code>num</code> vertically, however when I run it the only thing it prints are 0's. I know it gets the correct number of digits because it prints the same number of zeroes as there are digits in the number, so something must be wrong with my use of Modulo or Division here, and I can't quite seem to find it. Any help would be appreciated thank you!</p>
  
  <p>The function to get the numbers(maybe the problem is here?):</p>
  
  <pre><code>void getNum()
  {   
      int num, digits=0;
      printf("Enter a number to be printed vertically: ");
      scanf("%d", &amp;num);
  
      if(num &lt; 0)
      {
          digits = 1;
      }
      while(num)
      {
          num = num/10; //Here was the problem. Num was 0 once i passed it to print()
          digits++; //Simply added a new variable to fix it. Thanks all!
      }
  
      print(num, digits);
  }
  </code></pre>