title: Drawing a triangle in a 2-dimensional char array
body: <p>I'm trying to use a 2d char array as sort of a table for shapes and I'm having trouble trying to draw a triangle. Given the position of the top of the triangle and its height, my function is supposed to draw a triangle in a 25-row, 80-column char array by changing its elements that I've already assigned to ' ' initially.This is what I have so far:</p>
  
  <pre><code>int i, j;
  for(i=0; i&lt;height; i++){
      for(j=-i; j&lt;=i; j++){
          screen[x+i][y+j]=ch;
      }
  }    
  </code></pre>
  
  <p>screen is the name of my 2d char array.</p>
  
  <p>for example it should be like this for a triangle of height 3 :</p>
  
  <pre><code>  *
   ***
  *****    
  </code></pre>
  
  <p>but it doesn't seem to work for some reason and I can't see why.</p>
  
  <p>I apologize for not clarifying what my code does as it is.
  I have the below function to print my 2d array :</p>
  
  <pre><code>void PrintScreen(){
      int i, j;
      for(i=0; i&lt;SCREEN_HEIGHT; i++)
      {
          for(j=0; j&lt;SCREEN_WIDTH; j++)
          {
              printf("%c", screen[i][j]);
          }
          printf("\n");
      }
  } // end-PrintScreen
  </code></pre>
  
  <p>I figured out what I was doing wrong. I couldn't see anything I ran the program before because of a mistake I made. If anyone else needs help with the same problem, the code above should work fine.</p>