In C we use printf("\n");
for the next line. Is there any way to print again from the end of the previous line?
Asked
Active
Viewed 794 times
1

Jonathan Leffler
- 730,956
- 141
- 904
- 1,278
-
1Some terminals likely have a way to move the cursor up by sending a special code, or calling some other function. But that depends on your terminal software (or hardware); it's outside the scope of the C language itself. – Nate Eldredge Apr 08 '20 at 03:30
-
What about C++ or other languages? – Nur Mohammed Mehedy Hassan Apr 08 '20 at 03:35
-
Control-K might move up a line. Remember, in `vim`, you use `l` to go right (so intuitive!) `h` to go left, `j` to go down, `k` to go up – and the control-codes corresponding to those move right, left, down, up. OTOH, control-K may not work — it depends on the terminal (or terminal emulation) that you're using. If the cursors is at the start of a line, backspace, control-H, `\b` might move to the end of the previous line; again, it might not. – Jonathan Leffler Apr 08 '20 at 03:36
-
It's independent of programming language; it depends on the terminal (terminal emulator) characteristics. – Jonathan Leffler Apr 08 '20 at 03:36
-
Maybe this helps: https://stackoverflow.com/questions/26423537/how-to-position-the-input-text-cursor-in-c – Adrian Mole Apr 08 '20 at 03:40
-
There are xterm / vt100 control sequences for doing this. When you run CLI stuff that shows something like a progress bar on the terminal, it's writing content like this. – seand Apr 08 '20 at 03:40
-
@seand usually \r is enough for the progress bars – 0___________ Apr 08 '20 at 03:43
-
[man 4 console_codes](http://man7.org/linux/man-pages/man4/console_codes.4.html). (The command should work on Debian / Ubuntu based systems, at least.) – rici Apr 08 '20 at 03:57
1 Answers
0
You can use gotoxy() function to move your cursor to a specific point.like this It will get you to that specific point where you wanna be if you want some other method that hold on.
#include <stdio.h>
#include <conio.h>
int main()
{
int x, y;
x = 10;
y = 10;
gotoxy(x, y);
printf("C program to change cursor position.");
getch();
return 0;
}
other thing you can do is to keep printing the statement..it will show it as the new line being started from the end of previous line.

Gautam Goyal
- 230
- 1
- 4
- 16
-
1This isn't standard C though, but a very old MS DOS library which went obsolete some 20 years ago. What makes you think the OP (or anyone else) is still programming in MS DOS? – Lundin Apr 08 '20 at 11:33