I have this program that create a new line after every 10 characters. However, once it hits the second iteration and there after it only outputs 9 characters. The program works if I set the second i to -1 but I do not understand why it will not work with i set to 0. The logic is the exact same as the first run as the first i is only run once, so when I want a new line I reset i. Can someone explain what I am missing? I drew out the steps on paper but it still doesn't make sense. Thank you.
#include <stdio.h>
#include <ncurses.h>
#define MAXLINE 10
// count number of chars, once it reaches certain amount
int main (void)
{
//cbreak();
// to open curses terminal
initscr();
int i, c;
// first iteration set to 1
for (i = 0; (c = getch()) != EOF; i++)
{
if (i == (MAXLINE-1))
{
printf("\r\n");
i = 0; // Counter is reset. To break out of the loop use CTRL + D.
}
}
// to close curses terminal
endwin();
}