Problem with getchar method!

DC A adc4444@hotmail.com
Sat Jul 23 03:01:00 GMT 2005


Hi! I'm completely new at gnu c and I 've a problem with getchar() method. 
My program is given below. first it asks for a number than it shows the 
squared output which begins from 1 to that number. But after 24 output it 
supposed to stop and show a message "Press enter to continue..." and when 
pressed return key it should proceed with the calculation. My program shows 
the squarred output fine but it doesn't stop after 24 And also I don't want 
to use scanf. Can anyone please tell me where i am doing wrong?



-------------------------------------------------------------------------
#include <stdio.h>

int main()
{
  int i, n;
  int ch;


  printf("This program prints a table of squares.\n");
  printf("Enter number of entries in table: ");
  scanf("%d", &n);

  for (i = 1; i <= n; i++)
  {

   if( i == 25 )
   {
     do
     {
       printf("Press enter to continue...");
       ch = getchar();
     }
     while (ch != '\n');
    }

    printf("%10d%10d\n", i, i * i);
  }
  return 0;
}
------------------------------------------------------------------------


Thanks.

--ad4




More information about the Gcc mailing list