0
    int main(void)
    {

     printf("Number of blocks: "); //prompts the user for number of blocks
     int n; //height


     do
     {
     n = GetInt();
     }
     while ( n > 23 || n < 0);

     for(int i = 0; i < n; i++) //i = row
    {
     { 
      for(int sp = 0; sp - 1; sp--)  //sp = space
       printf(" "); 
    }

     for(int c = 0; c < (i+2); c++) //c = column
   {

     printf("#");

   }


   printf("\n");
  }   

  }

https://gyazo.com/8daa119258ea28847b0be9ee2a854079infinite loop

This is my code for mario. No problems when I compile it. However, when I execute it and enter a number between the valid parameters (0-23) I get stuck on an infinite loop (as shown in the image) and I'm required to do CTRL + C to forcefully exit.

I don't want a direct answer, just point a direction to which I could follow.

Thank you in advance.

2
  • 1
    Firstly I would advise you to implement your code in a way respecting basic rules of style50 (implementation 4 x 4 tab, ...). Once done, you will have a much more comprehensive view of what your code is doing, from nested loops to exterior ones. Also, what your while loop supposed to do? At the moment, I think a review of your code implementation will clearly help you, and us, to find where errors come from. – CharlesD89 Nov 11 '15 at 15:11
  • Thanks, this actually helped me a lot ! – Gabriel Nov 13 '15 at 21:10
0

Since you wanted a pointer in the right direction instead of a specific answer, here it is. You have a broken for loop declaration. The second clause should be a test of some kind. When it isn't a test, i.e., missing something like >, <, ==, etc., it is often interpreted as always true, so it will never terminate.

BTW, the while loop is doing exactly what it should, although I might add a prompt for a number, as specified in the spec.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .