#include <stdio.h>
#include <stdlib.h>
#include <ncurses.h>
#include <unistd.h> // For sleep function
int main() {
initscr(); // Initialize ncurses
printf("Press 'q' to exit...\n");
sleep(2);
clear();
refresh();
cbreak(); // Enable 'cbreak' mode, which doesn't wait for Enter key
noecho(); // Disable echoing of typed characters
nodelay(stdscr, TRUE); // Set getch() to be non-blocking
for (;;) {
int ch = getch(); // Read a single character without blocking
if (ch == 'q') {
printf("Exiting...\n");
sleep(2);
break;
}
printf("Message every 1 second...\n");
refresh(); // Refresh the ncurses screen
sleep(1); // Wait for 1 second
}
endwin(); // End ncurses
return 0;
}
Yes, you can run a for loop in C without a test condition, like this:my question is can we run a for loop in c without a test condition?
like this:
for( ; ; )
will this run the code in the for block or will this turn out to be false?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.