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;
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
c arrays linux printf output
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
|
show 1 more comment
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
|
show 1 more comment
2 Answers
2
active
oldest
votes
(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
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
add a comment |
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
(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
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
add a comment |
(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
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
add a comment |
(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
(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
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
add a comment |
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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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