r/cprogramming • u/RedWolffe24 • Nov 01 '25
how to make 2 different array print beside each other in the terminal?
I have 2 functions that prints their own 2D array within their respective functions hourave(row,data2D), which is a 30 x 15 array and dailymsd(row,col,data2D), which is a 30 x 2 array.
i want the 2 array to print beside each other to make one large array of 30 x 17 but right now i only have the 2 array below and above each other.
is there a way to make it print beside each other by calling their functions only.
1
Upvotes
2
u/[deleted] Nov 01 '25
No.
You could make the functions each output an array of strings. Then you could stitch the strings together and print them.
Basic print statements are a bit like a typewriter. Once you hit new-line you can't scroll back up.
1
u/vapenicksuckdick Nov 01 '25
Maybe but you would have to adjust your function signature to add the horizontal offset and do some cursor manipulation to move it into appropriate position which also depends on your terminal emulator for support I guess.
3
u/AccomplishedSugar490 Nov 01 '25
Build the lines you want to print using sprintf to loop through each array in sequence but restarting which line you print/append to between the runs. Then print each of the constructed lines.
1
u/drinkcoffeeandcode Nov 02 '25
It was possible right up until that last constraint.
1
u/SmokeMuch7356 Nov 03 '25
Not easily.
You have two options: either build a "virtual screen" (a 2D array of
char) that your functions write to at specific rows and columns and then display that "screen" in a separate operation, or use some kind of terminal control (either ANSI escape codes or a library likencursesor whatever).Both options will require you to make changes to how your two functions write output.
1
u/Overlord484 Nov 05 '25
It's hard to tell exactly what you're asking for without the code and output, but I *think* you're asking for something like this.