title: Scrolling in C with ncurses pad
body: <p>I'm trying to get a window in ncurses where i write the result of a mysql-query. But the query returns more lines than i have in my terminal.
  So I tried to create a pad, so that i can scroll through the results.</p>
  
  <p>But the problem is, that there is no pad visible on my terminal.</p>
  
  <p>I just simplified the code, but it's still not working for me:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;ncurses.h&gt;
  #include &lt;mysql.h&gt;
  #include &lt;my_global.h&gt;
  
  WINDOW *pad;
  MYSQL *con;
  
  static int mrow, mcol;
  static char *host, *user, *pass;
  
  void quit(void)
  {
    // close MySQL connection
    mysql_close(con);
    // end curses
    endwin();
  }
  
  
  int main(int argc, char **argv)
  {
    // initialize curses
    initscr();
    atexit(quit);
    clear();
    cbreak();
    keypad(stdscr, TRUE);
    start_color();
  
    // get terminal size
    getmaxyx(stdscr, mrow, mcol);
  
    // open MySQL connection
    host = "localhost";
    user = "root";
    pass = "8$oP.4L!";
    con = mysql_init(NULL);
    if (con == NULL)
    {
      exit(1);
    }
    if (mysql_real_connect(con, host, user, pass, NULL, 0, NULL, 0) == NULL)
    {
      mysql_close(con);
      exit(1);
    }
  
    // Cursor off
    curs_set(0);
  
    // Get SQL Data
    char *query = "SELECT IF((SELECT name FROM zeiterf.stdjobs WHERE nr = zeiterf.wtime.job) != '', (SELECT name FROM zeiterf.stdjobs WHERE nr = zeiterf.wtime.job), job), IF(usr != '', (SELECT vname FROM zeiterf.user WHERE nr = zeiterf.wtime.usr), NULL), IF(usr != '', (SELECT nname FROM zeiterf.user WHERE nr = zeiterf.wtime.usr), NULL), SEC_TO_TIME(SUM(TIME_TO_SEC(tout) - TIME_TO_SEC(tin))) FROM zeiterf.wtime WHERE tout != 0 AND job != '...ENDE' GROUP BY job , usr WITH ROLLUP;";
    if (mysql_query(con, query))
    {
      exit (1);
    }
  
    MYSQL_RES *result = mysql_store_result(con);
    MYSQL_ROW *row;
    int num_fields = mysql_num_fields(result);
    int rowcount = mysql_num_rows(result);
  
    // create pad
    pad = newpad (rowcount + 1, mcol);
  
    // col titles
    wprintw(pad, "Auftrag \tName \t\t\tZeit\n");
  
    while (row = mysql_fetch_row(result))
    {
      int i = 0;
  
      for (i = 0; i &lt; num_fields; i++)
      {
        wprintw(pad, "%s\t", row[i]); 
      }
  
      wprintw(pad, "\n");
    }
  
    mysql_free_result(result);
  
    // Show content of pad
    int mypadpos = 0;
    prefresh(pad, mypadpos, mcol, 0, 0, mrow, mcol);
  
    // wait for exit key
    int ch;
    while((ch = wgetch(pad)) != 'q')
    {
      switch (ch)
      {
        case KEY_UP:
          if (mypadpos &gt;= 0)
      {
        mypadpos--;
      }
      prefresh(pad, mypadpos, mcol, 0, 0, mrow, mcol);
      break;
        case KEY_DOWN:
      if (mypadpos &lt;= rowcount+1)
      {
        mypadpos++;
      }
      prefresh(pad, mypadpos, mcol, 0, 0, mrow-1, mcol);
      break;
       }
    }
  
    // remove window
    delwin(pad);
    clear();
    refresh();
  
    return (0);
  }
  </code></pre>
  
  <p>compiled with </p>
  
  <pre><code>gcc -o test testpad.c `mysql_config --libs --cflags` -lncurses
  </code></pre>
  
  <p>on my Debian Sid system. Also tried on my RPi with raspbian. On both systems same behavior.</p>
  
  <p>Can anyone tell me what i did wrong?</p>