c - Updating/Refreshing text displayed on the terminal -


i'm attempting create game of life program in c, i'm not familiar process update output displayed on terminal.

so, example, have 2d char array, each element contain either '#' or '-'. print array onto screen, rather printing new 2d array every time there state change, want overwrite old array in terminal new state.

i have looked ways this, haven't had luck. closest have found carriage return in printf function (\r), can tell me best way this.

specifically, how print out 2d array on screen, change elements of array, , print out new array on top of old one, ie, overwrite it.

(some of these links, code snippets linux, , others windows)
given specific questions, (and assuming know how write array console) :

1) write first array.
2) clear console (or over write console)
this:

#include <stdlib.h>  void main() {    system("cls"); }      

or write following stdout: (linux)

write(1,"\e[h\e[2j",7); 

which /usr/bin/clear except not create process.
or both:

 void clear_screen()  {   #ifdef windows      system ( "cls" );   #else      // assume posix      system ( "clear" );   #endif  }   

more options here

3) write next array


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -