Can I control the starting line and column number of print using the printf function in C? IF so , how? And if not is there any other function or method which can be used to do the same?. Thanks.
Asked
Active
Viewed 221 times
0
-
1Can we know what exactly you want to do ? – haccks Jun 30 '14 at 17:09
-
Some terminals support [VT100 control codes](http://www.termsys.demon.co.uk/vtansi.htm) which includes cursor control. Also read about [ncurses](http://en.wikipedia.org/wiki/Ncurses) and the [Windows console functions](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx). – Some programmer dude Jun 30 '14 at 17:09
-
You can't control the column; `printf()` starts printing in column 1. If you want the output to start in column N (N > 1), then you have to ensure that N-1 blanks (or equivalent) are generated first. – Jonathan Leffler Jun 30 '14 at 17:11
-
The C standard doesn't say that `stdout` is a terminal. Could be a regular file, a network device, a screen reader, a pipe, a human being reading the output loudly… There needn't be anything like lines and columns. – mafso Jun 30 '14 at 17:37
-
@haccks I want to be able to print two lines and then clear screen several times continiously.. I cannot use #include
as im using the cc command and #include – user3750601 Jun 30 '14 at 18:27is not supported in gcc.. Is there anyway i can clear screen through the program and not the command prompt.. -
1Clearing the screen in not a part of C, but a part of your target system's terminal. Various terminals will clear depending on control codes such as `'\v'` vertical tab, escape sequences, etc. Need to know the terminal or its family. – chux - Reinstate Monica Jun 30 '14 at 19:44
1 Answers
1
With standard C it is not possible, there are some escape sequences which you can use under Linux and maybe it is possible (I haven't tested it, I know you can change the foreground and background colors). Under Linux you can try the library ncurses
which does what you want.
-
1"With standard C it is not possible" definitely gotta disagree there. ncurses itself is a c library. – Brandon Yates Jun 30 '14 at 17:43
-
When I said "With standard C it is not possible", I meant not using additional libraries. As far as I know there is no port of ncurses to Windows (http://stackoverflow.com/questions/138153/is-ncurses-available-for-windows). We don't know whether he/she is using Linux or Windows. – Jul 01 '14 at 03:28