Updating text displayed on the terminalModify text already in the terminalClear or replace console outputPrinting leading 0's in C?memory leak in a formatting string, correct null terminationHow do I find all files containing specific text on Linux?How to get the current date and time in the terminal and set a custom command in terminal for it?C char array printing as string error with accepting null termination?Printf on bytearrayHow can I quickly printf 2 dimensional array of chars made of pointers to pointers without using a loop?C - Ways to display information on terminal quickerPrintf not working for array of doublesC: Is there a way to lower the speed of printf-outputs

Why do players in the past play much longer tournaments than today's top players?

What is a solution?

Why didn't Thanos kill all the Dwarves on Nidavellir?

What was the definition of "set" that resulted in Russell's Paradox

How would vampires avoid contracting diseases?

How can one write good dialogue in a story without sounding wooden?

What's the point of having a RAID 1 configuration over incremental backups to a secondary drive?

Why does the U.S. tolerate foreign influence from Saudi Arabia and Israel on its domestic policies while not tolerating that from China or Russia?

How many hours would it take to watch all of Doctor Who?

Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?

How would my creatures handle groups without a strong concept of numbers?

Why isn't pressure filtration popular compared to vacuum filtration?

How can I effectively communicate to recruiters that a phone call is not possible?

How to tell someone I'd like to become friends without causing them to them think I'm romantically interested in them?

How can I deal with a player trying to insert real-world mythology into my homebrew setting?

When casting Eldritch Blast with the Agonizing Blast eldritch invocation, what do I add to my damage roll?

definition of "percentile"

Is "I do not want you to go nowhere" a case of "DOUBLE-NEGATIVES" as claimed by Grammarly?

C program to parse source code of another language

Why are Hobbits so fond of mushrooms?

Why did Harry Potter get a bedroom?

Changing trains in the Netherlands

Combining latex input and sed

How to wire 3 hots / 3 neutrals into this new TR outlet with 2 screws?



Updating text displayed on the terminal


Modify text already in the terminalClear or replace console outputPrinting leading 0's in C?memory leak in a formatting string, correct null terminationHow do I find all files containing specific text on Linux?How to get the current date and time in the terminal and set a custom command in terminal for it?C char array printing as string error with accepting null termination?Printf on bytearrayHow can I quickly printf 2 dimensional array of chars made of pointers to pointers without using a loop?C - Ways to display information on terminal quickerPrintf not working for array of doublesC: Is there a way to lower the speed of printf-outputs






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I'm attempting to create a game of life program in C, but i'm not very familiar with a process to update the output displayed on the terminal.



So, for example, I will have a 2d char array, where each element will contain either a '#' or a '-'. I will print this array onto the screen, but rather than printing a new 2d array every time there is a state change, I want to overwrite the old array in the terminal with the new state.



I have looked for ways to do this, but haven't had much luck. The closest I have found is a carriage return in the printf function (r), but hopefully someone can tell me the best way to do this.



Specifically, how could I print out a 2d array on the screen, change the elements of the array, and print out the new array ON TOP of the old one, ie, overwrite it.










share|improve this question



















  • 1





    Do you have a specific question?

    – this
    Apr 21 '14 at 20:21











  • I have updated the question

    – syco_link
    Apr 21 '14 at 20:27











  • What do you mean by on top?

    – this
    Apr 21 '14 at 20:27











  • Windows, Linux, iOS... ?

    – ryyker
    Apr 21 '14 at 21:14











  • Sorry, Linux platform

    – syco_link
    Apr 21 '14 at 21:27

















2















I'm attempting to create a game of life program in C, but i'm not very familiar with a process to update the output displayed on the terminal.



So, for example, I will have a 2d char array, where each element will contain either a '#' or a '-'. I will print this array onto the screen, but rather than printing a new 2d array every time there is a state change, I want to overwrite the old array in the terminal with the new state.



I have looked for ways to do this, but haven't had much luck. The closest I have found is a carriage return in the printf function (r), but hopefully someone can tell me the best way to do this.



Specifically, how could I print out a 2d array on the screen, change the elements of the array, and print out the new array ON TOP of the old one, ie, overwrite it.










share|improve this question



















  • 1





    Do you have a specific question?

    – this
    Apr 21 '14 at 20:21











  • I have updated the question

    – syco_link
    Apr 21 '14 at 20:27











  • What do you mean by on top?

    – this
    Apr 21 '14 at 20:27











  • Windows, Linux, iOS... ?

    – ryyker
    Apr 21 '14 at 21:14











  • Sorry, Linux platform

    – syco_link
    Apr 21 '14 at 21:27













2












2








2








I'm attempting to create a game of life program in C, but i'm not very familiar with a process to update the output displayed on the terminal.



So, for example, I will have a 2d char array, where each element will contain either a '#' or a '-'. I will print this array onto the screen, but rather than printing a new 2d array every time there is a state change, I want to overwrite the old array in the terminal with the new state.



I have looked for ways to do this, but haven't had much luck. The closest I have found is a carriage return in the printf function (r), but hopefully someone can tell me the best way to do this.



Specifically, how could I print out a 2d array on the screen, change the elements of the array, and print out the new array ON TOP of the old one, ie, overwrite it.










share|improve this question
















I'm attempting to create a game of life program in C, but i'm not very familiar with a process to update the output displayed on the terminal.



So, for example, I will have a 2d char array, where each element will contain either a '#' or a '-'. I will print this array onto the screen, but rather than printing a new 2d array every time there is a state change, I want to overwrite the old array in the terminal with the new state.



I have looked for ways to do this, but haven't had much luck. The closest I have found is a carriage return in the printf function (r), but hopefully someone can tell me the best way to do this.



Specifically, how could I print out a 2d array on the screen, change the elements of the array, and print out the new array ON TOP of the old one, ie, overwrite it.







c arrays linux printf output






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 2:32









jww

56.3k42 gold badges249 silver badges540 bronze badges




56.3k42 gold badges249 silver badges540 bronze badges










asked Apr 21 '14 at 20:19









syco_linksyco_link

669 bronze badges




669 bronze badges







  • 1





    Do you have a specific question?

    – this
    Apr 21 '14 at 20:21











  • I have updated the question

    – syco_link
    Apr 21 '14 at 20:27











  • What do you mean by on top?

    – this
    Apr 21 '14 at 20:27











  • Windows, Linux, iOS... ?

    – ryyker
    Apr 21 '14 at 21:14











  • Sorry, Linux platform

    – syco_link
    Apr 21 '14 at 21:27












  • 1





    Do you have a specific question?

    – this
    Apr 21 '14 at 20:21











  • I have updated the question

    – syco_link
    Apr 21 '14 at 20:27











  • What do you mean by on top?

    – this
    Apr 21 '14 at 20:27











  • Windows, Linux, iOS... ?

    – ryyker
    Apr 21 '14 at 21:14











  • Sorry, Linux platform

    – syco_link
    Apr 21 '14 at 21:27







1




1





Do you have a specific question?

– this
Apr 21 '14 at 20:21





Do you have a specific question?

– this
Apr 21 '14 at 20:21













I have updated the question

– syco_link
Apr 21 '14 at 20:27





I have updated the question

– syco_link
Apr 21 '14 at 20:27













What do you mean by on top?

– this
Apr 21 '14 at 20:27





What do you mean by on top?

– this
Apr 21 '14 at 20:27













Windows, Linux, iOS... ?

– ryyker
Apr 21 '14 at 21:14





Windows, Linux, iOS... ?

– ryyker
Apr 21 '14 at 21:14













Sorry, Linux platform

– syco_link
Apr 21 '14 at 21:27





Sorry, Linux platform

– syco_link
Apr 21 '14 at 21:27












2 Answers
2






active

oldest

votes


















1














(some of these links, code snippets are Linux, and others are Windows)
Given your specific questions, (and assuming you do know how to write an array to the console) :



1) write the first array.
2) Then Clear The Console (or over write the console)

Something like this:



#include <stdlib.h>

void main()

system("cls");



Or write the following to stdout: (Linux)



write(1,"E[HE[2J",7);


which is what /usr/bin/clear does except it does not create another process.
Or both:



 void clear_screen()

#ifdef WINDOWS
system ( "CLS" );
#else
// Assume POSIX
system ( "clear" );
#endif



More Options Here



3) write the next array






share|improve this answer

























  • Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

    – syco_link
    Apr 22 '14 at 1:56











  • @syco_link - Yes, that work thing kind of gets in the way sometimes.

    – ryyker
    Apr 22 '14 at 14:58












  • Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

    – syco_link
    Apr 22 '14 at 21:35











  • Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

    – ryyker
    Apr 22 '14 at 21:52



















0














You can try something like this:



#include<stdio.h>

int main(void)


printf ("#####-----r");
printf ("-#####----r");




Not sure if I really answered your question. And if this is not your answer then you are definitely looking for something like ncurses.






share|improve this answer

























  • Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

    – syco_link
    Apr 21 '14 at 21:28














Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23205280%2fupdating-text-displayed-on-the-terminal%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














(some of these links, code snippets are Linux, and others are Windows)
Given your specific questions, (and assuming you do know how to write an array to the console) :



1) write the first array.
2) Then Clear The Console (or over write the console)

Something like this:



#include <stdlib.h>

void main()

system("cls");



Or write the following to stdout: (Linux)



write(1,"E[HE[2J",7);


which is what /usr/bin/clear does except it does not create another process.
Or both:



 void clear_screen()

#ifdef WINDOWS
system ( "CLS" );
#else
// Assume POSIX
system ( "clear" );
#endif



More Options Here



3) write the next array






share|improve this answer

























  • Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

    – syco_link
    Apr 22 '14 at 1:56











  • @syco_link - Yes, that work thing kind of gets in the way sometimes.

    – ryyker
    Apr 22 '14 at 14:58












  • Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

    – syco_link
    Apr 22 '14 at 21:35











  • Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

    – ryyker
    Apr 22 '14 at 21:52
















1














(some of these links, code snippets are Linux, and others are Windows)
Given your specific questions, (and assuming you do know how to write an array to the console) :



1) write the first array.
2) Then Clear The Console (or over write the console)

Something like this:



#include <stdlib.h>

void main()

system("cls");



Or write the following to stdout: (Linux)



write(1,"E[HE[2J",7);


which is what /usr/bin/clear does except it does not create another process.
Or both:



 void clear_screen()

#ifdef WINDOWS
system ( "CLS" );
#else
// Assume POSIX
system ( "clear" );
#endif



More Options Here



3) write the next array






share|improve this answer

























  • Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

    – syco_link
    Apr 22 '14 at 1:56











  • @syco_link - Yes, that work thing kind of gets in the way sometimes.

    – ryyker
    Apr 22 '14 at 14:58












  • Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

    – syco_link
    Apr 22 '14 at 21:35











  • Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

    – ryyker
    Apr 22 '14 at 21:52














1












1








1







(some of these links, code snippets are Linux, and others are Windows)
Given your specific questions, (and assuming you do know how to write an array to the console) :



1) write the first array.
2) Then Clear The Console (or over write the console)

Something like this:



#include <stdlib.h>

void main()

system("cls");



Or write the following to stdout: (Linux)



write(1,"E[HE[2J",7);


which is what /usr/bin/clear does except it does not create another process.
Or both:



 void clear_screen()

#ifdef WINDOWS
system ( "CLS" );
#else
// Assume POSIX
system ( "clear" );
#endif



More Options Here



3) write the next array






share|improve this answer















(some of these links, code snippets are Linux, and others are Windows)
Given your specific questions, (and assuming you do know how to write an array to the console) :



1) write the first array.
2) Then Clear The Console (or over write the console)

Something like this:



#include <stdlib.h>

void main()

system("cls");



Or write the following to stdout: (Linux)



write(1,"E[HE[2J",7);


which is what /usr/bin/clear does except it does not create another process.
Or both:



 void clear_screen()

#ifdef WINDOWS
system ( "CLS" );
#else
// Assume POSIX
system ( "clear" );
#endif



More Options Here



3) write the next array







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 21 '14 at 21:43

























answered Apr 21 '14 at 21:07









ryykerryyker

13k2 gold badges29 silver badges61 bronze badges




13k2 gold badges29 silver badges61 bronze badges












  • Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

    – syco_link
    Apr 22 '14 at 1:56











  • @syco_link - Yes, that work thing kind of gets in the way sometimes.

    – ryyker
    Apr 22 '14 at 14:58












  • Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

    – syco_link
    Apr 22 '14 at 21:35











  • Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

    – ryyker
    Apr 22 '14 at 21:52


















  • Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

    – syco_link
    Apr 22 '14 at 1:56











  • @syco_link - Yes, that work thing kind of gets in the way sometimes.

    – ryyker
    Apr 22 '14 at 14:58












  • Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

    – syco_link
    Apr 22 '14 at 21:35











  • Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

    – ryyker
    Apr 22 '14 at 21:52

















Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

– syco_link
Apr 22 '14 at 1:56





Ryyker, apologies for not commenting sooner, have been at work. This looks like it might be exactly what i've been looking for! I will try this out later and tick the solution if all good. Thanks :)

– syco_link
Apr 22 '14 at 1:56













@syco_link - Yes, that work thing kind of gets in the way sometimes.

– ryyker
Apr 22 '14 at 14:58






@syco_link - Yes, that work thing kind of gets in the way sometimes.

– ryyker
Apr 22 '14 at 14:58














Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

– syco_link
Apr 22 '14 at 21:35





Cleared the screen perfectly, exactly what I was after! Is there any chance you could explain the expression in the write function, or point me towards some documentation for it? Thank you!

– syco_link
Apr 22 '14 at 21:35













Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

– ryyker
Apr 22 '14 at 21:52






Search for "EHE[2J" [HERE. It is essentially shell scripting. Lots written on it, very useful.

– ryyker
Apr 22 '14 at 21:52














0














You can try something like this:



#include<stdio.h>

int main(void)


printf ("#####-----r");
printf ("-#####----r");




Not sure if I really answered your question. And if this is not your answer then you are definitely looking for something like ncurses.






share|improve this answer

























  • Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

    – syco_link
    Apr 21 '14 at 21:28
















0














You can try something like this:



#include<stdio.h>

int main(void)


printf ("#####-----r");
printf ("-#####----r");




Not sure if I really answered your question. And if this is not your answer then you are definitely looking for something like ncurses.






share|improve this answer

























  • Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

    – syco_link
    Apr 21 '14 at 21:28














0












0








0







You can try something like this:



#include<stdio.h>

int main(void)


printf ("#####-----r");
printf ("-#####----r");




Not sure if I really answered your question. And if this is not your answer then you are definitely looking for something like ncurses.






share|improve this answer















You can try something like this:



#include<stdio.h>

int main(void)


printf ("#####-----r");
printf ("-#####----r");




Not sure if I really answered your question. And if this is not your answer then you are definitely looking for something like ncurses.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 21 '14 at 20:36

























answered Apr 21 '14 at 20:30









bubblebubble

1,7794 gold badges24 silver badges48 bronze badges




1,7794 gold badges24 silver badges48 bronze badges












  • Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

    – syco_link
    Apr 21 '14 at 21:28


















  • Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

    – syco_link
    Apr 21 '14 at 21:28

















Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

– syco_link
Apr 21 '14 at 21:28






Sorry, the array is 2d so it might be a 10 x 10 grid on the terminal. As far as i'm aware r will only deal with one line and no more, but I shall look into ncurses, thanks!

– syco_link
Apr 21 '14 at 21:28


















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23205280%2fupdating-text-displayed-on-the-terminal%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현