Is it possible to clear last input on display without clearing hall display using system("cls") or fflush(stdout)?I want to make timer so i need to delete last input to show new time...
Is it possible to clear last input on display without clearing hall display using system("cls") or fflush(stdout)?I want to make timer so i need to delete last input to show new time...
fflush(stdout) will not clear the display, it only sends what's in the output buffer to screen. Generally to do screen tricks like this you need a screen library like curses/ncurses. A workaround is to print the backspace character to back up the cursor over the printed time, print the time then call fflush(stdout). You can't put a newline after the time though. Not sure how portable that is either.
No portable way.
In the same line you can try
for all line-chars and then put space(s)Code:putchar('\b');
There are escape-sequences, which can help you.Code:putchar(' ');
Thanks. What I have to change in this code to make it working properly?After printing 10 it prints 90.
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> main () { time_t b,e; e=time(NULL); b=e; printf("\nTimer: "); while(time(NULL)!=(e+20)) { if(b!=time(NULL)){ if(((e+20)-time(NULL))>=9){printf("\b");} printf("\b%d",(e+20)-time(NULL)); b++; } } system("pause"); }
For starters, you need to properly declare main and return an integer at the end of it (read this link). You also need to work on formatting your code (don't cram multiple statements onto one line, and put some space around your operators), picking better variable names and writing useful comments so that the rest of the world can understand what your code is trying to do.
Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main () { time_t b,e; e=time(NULL); // current time b=e; printf("\nTimer: "); while(time(NULL)!=(e+20)) { // e+20 is end time if(b!=time(NULL)){ //usage of b is to prevent printing after each pass through the loop if(e+20-time(NULL)>=9)printf("\b"); printf("\b%d",e+20-time(NULL)); b++; } } system("pause"); return 0; }