The problem here is that you're thinking from 1 instead of from 0. In C the first of anything is numbered zero. This shows in your incorrect ruler; the left-hand column is zero, not 1, and if the screen is 30 characters wide then the right hand column is column 29 not 30.

So both triangle and position are 1-based, and this is why your triangle is clipped 2 characters early. One fix is to add a fudge factor of 2 to screenWidth: "for (int triangle = 1; triangle < i && (triangle + position) <= screenWidth+2; triangle++)" and "if (triangle + position >= screenWidth+2)"; another (harder but better) solution is to modify the code so that the first of anything is counted as zero instead of 1.

If anything needs numbering from 1 for the user's convenience, then work internally with zero-based numbering and convert between 1-based and 0-based at input/output, rather than trying to work with 1-based variables in the code. After 28 years of programming this is my conclusion having spent countless hours trying to make code work by adding +1 and -1 fudge factors all over the place.

So for example screenWidth of 30 is fine as is, just count x from 0-29 (and display x+1, thus performing the conversion back to 1-based at output); triWidth=20 is also OK and count from 0-19. position=21 from the user's point of view so this is 20 from the programmer's point of view. Keep position as 21 if you like and remember it's a 1-based number (which means you have to add a -1 fudge every time you use it), or deduct 1 after input (converting it to 0-based at input) so you don't have to remember and can just use it as is.