title: My code functions with a printf statement, but not without it
body: <p>Adding the printf("Hi!\n") statements allows the code to work. It also works if the bound initial bound is improper and the user enters a new one. When I ran some tests calculate divers sometimes returned a character instead of an integer. I'm thinking it has something to do with my memory allocation. I also noticed that ./a.out 6 10 "|" would work but ./a.out 6 25 "|" would not causing an infinite loop when printing the lines of "|".</p>
  
  <p><a href="https://i.stack.imgur.com/gohZZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gohZZ.png" alt="enter image description here"></a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  // Structs
  typedef struct data_struct {
      int lineNumber;
      int divisorSum;
      char type[10];
  }data;
  
  // Prototypes
  int calculateDivsors(int integer);
  
  // Functions
  int main (int argc, char *argv[]) {
  
      int lowerBound;
      int upperBound;
      char character;
  
      // Gets the values from command-line
      sscanf(argv[1], "%d", &amp;lowerBound);
      sscanf(argv[2], "%d", &amp;upperBound);
      sscanf(argv[3], "%c", &amp;character);
  
      // Check to see if bound is proper
      while (upperBound &lt;= lowerBound || lowerBound &lt; 2) {
          printf("Error, please enter a new range (positive increasing).\n");
          scanf("%d %d", &amp;lowerBound, &amp;upperBound);
      }
  
      // Structure calls
      data* info = NULL;
      int totalData = upperBound - lowerBound;
  
      // Allocate the memory
      info = (data*)malloc(totalData * sizeof(data));
  
      printf("Hi!\n");
  
      if (info != NULL) {
          // Iterate through all the digits between the two bounds
          for (int i = lowerBound; i &lt;= upperBound; i++) {
              int sum = calculateDivsors(i);
  
  
              // Write data to indiviual structures
              info[i].lineNumber = i;
              info[i].divisorSum = sum;
  
              // Check to see if the sum is greater than, less than, or equal to the original
              if (sum == i) {
                  strcpy(info[i].type, "Perfect");
              }
  
              else if (sum &gt; i) {
                  strcpy(info[i].type, "Abundant");
              }
  
              else if (sum &lt; i) {
                  strcpy(info[i].type, "Deficient");
              }
  
              // Line n# has a column width of 4, string of 10
              printf("%4d is %-10s\t", info[i].lineNumber, info[i].type);
  
              // Generate Pictogram
              for (int j = 0; j &lt; info[i].divisorSum; j++) {
                  printf("%c", character);
              }
              printf("\n");
          }
  
      }
  }
  
  // Adds up the sum of diviors
  int calculateDivsors(int integer) {
  
      int sum = 0; 
  
      for (int i = 1; i &lt; integer; i++) {
          // Add to sum if perfectly i is a sum of integer
           if (integer % i == 0) {
              sum += i;
          }
      }
  
   return sum; // Returns the sum of diviors
  }
  </code></pre>