473,847 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a library function for placing cursor position in the cosole?

Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?

I was able to do this in Windows with a Windows.h function, but I want
to also do it on Linux/Unix as well.

I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group. But if someone knew it off
the top of their head, I won't stop you from writing it in a post! ;)
;)

Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console. This way, I can
keep my code more portable.

Nov 14 '05 #1
25 2683

"JeffS" <ja****@yahoo.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)
That's because standard C does not support direct device
access. All i/o is abstracted as 'streams of characters'.
C does not require the existence of a video display at all.

Is there a library function for placing the cursor position in the
console?
There are many, but all all platform-dependent. Also many implementations
provide library 'extensions' for this sort of thing, when applicable.
You might want to check your documentation for that.
Or is it something that can only be done with a platform API
call?
Essentially yes. But there are some third-party 'portable'
libraries available too.

I was able to do this in Windows with a Windows.h function, but I want
to also do it on Linux/Unix as well.
Sounds like you want some (relatively) 'portable' method. 'curses'
is one possiblity.


I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group. But if someone knew it off
the top of their head, I won't stop you from writing it in a post! ;)
;)

Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console.
There is not.
This way, I can
keep my code more portable.


Well, I hope you find my comments helpful anyway.

-Mike
Nov 14 '05 #2
>Is there a library function for placing the cursor position in the
console?
Which console? What cursor? An ASR33 teletype doesn't have a
cursor. (I suspect C was originally developed on this kind of
terminal, although maybe something older than the ASR33.)

Remember also that many operating systems provide ways to direct
stdin and stdout to something else, like files or pipes.
Or is it something that can only be done with a platform API
call?
Some hardware doesn't HAVE a cursor (printing terminals, for
example). Some hardware doesn't HAVE a coin return slot, either.
I was able to do this in Windows with a Windows.h function, but I want
to also do it on Linux/Unix as well.
If you know what the type of CRT terminal is (or what it emulates)
such as VT100, there is a specific character sequence you can send
it to position the cursor (generally, independent of the OS, but
dependent on the character set.). But you don't know that. It may
not even be the same terminal type on two different terminals
connected to the same Linux machine. And thanks to dialup ports
and network connections, there may not be a way to figure this out
by looking at the hardware of the machine itself.
I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group. But if someone knew it off
the top of their head, I won't stop you from writing it in a post! ;)
;)

Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console. This way, I can
keep my code more portable.


Your code is not very portable if it expects to be connected to
a console.

Gordon L. Burditt
Nov 14 '05 #3
JeffS wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?

I was able to do this in Windows with a Windows.h function, but I want
to also do it on Linux/Unix as well.

I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group. But if someone knew it off
the top of their head, I won't stop you from writing it in a post! ;)
;)

Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console.
This way, I can keep my code more portable. man ncurses


ncurses(3X) ncurses(3X)

NAME
ncurses - CRT screen handling and optimization package

SYNOPSIS
#include <curses.h>

DESCRIPTION
The ncurses library routines give the user a
terminal-independent method of updating character screens
with reasonable optimization.
This implementation is ‘‘new curses’’ (ncurses) and is
the approved replacement for 4.4BSD classic curses,
which has been discontinued.
Nov 14 '05 #4

"JeffS" <ja****@yahoo.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
<snip>
I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group.


<OT>
Good. Linux does not have one.
</OT>
Nov 14 '05 #5
"JeffS" <ja****@yahoo.c om> wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console?
You can't have scoured very hard. Next time, use a steel brush.
<http://www.eskimo.com/~scs/C-faq/q19.4.html>.
Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console.


There are very good reasons why there isn't such a function in the
Standard, one of which is that it would be hard to come up with an
interface which is both useful and portably implementable. Consider, for
example, that you have no way (and there may _be_ no way) to tell
whether stdout is connected to a local console, or to a line printer on
the other end of a long serial connection.

Richard
Nov 14 '05 #6
On 14 Dec 2004 16:43:36 -0800, JeffS
<ja****@yahoo.c om> wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?
The concepts 'console' and 'cursor' are inherently platform-specific
(try positioning a cursor on a Teletype(R) Model 33!). It is therefore
OT for c.l.c (but see below for suggestions).
I was able to do this in Windows with a Windows.h function, but I want
to also do it on Linux/Unix as well.
If you are dealing with a text-mode console, look for curses. It is
available on all Unices I know and under Cygwin for MSWin32 systems.
I won't ask for a Linux API call that positions the cursor, as that is
beyond the scope of the comp.lang.c group. But if someone knew it off
the top of their head, I won't stop you from writing it in a post! ;)
;)
<ESC>[a;bH

a and b are the row and column number in decimal ASCII (1,1 is the top
LH corner). That's the VT100/ANSI cursor control sequence, which works
with xterms, but of course is not guaranteed to work on anything else.
Anyway, it would be really ideal if there were a standard C library
function that postitions the cursor in the console. This way, I can
keep my code more portable.


The curses library (implemented by ncurses and others) has its own
standard from XSI.

HTH

Chris C
Nov 14 '05 #7
On Wed, 15 Dec 2004 11:31:50 +0000, Chris Croughton wrote:
On 14 Dec 2004 16:43:36 -0800, JeffS
<ja****@yahoo.c om> wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?
The concepts 'console' and 'cursor' are inherently platform-specific


To a degree but libraries like Curses have shown you have create a pretty
portable programming model for them.
(try positioning a cursor on a Teletype(R) Model 33!).
The fact that you can find environments that don't support this doesn't
invalidate the creation of a portable API for those that do. Such an
interface could simply say "Sorry can't do that" where that is
appropriate. Some programs (well any program) just can't run usefully on
platforms with inadequate functionality, that's true of standard C as it
is.
It is therefore OT for c.l.c (but see below for suggestions).


It is OT because the C language designers chose not to provide such
support in standard C, not because they couldn't have done. Curses exists
despite things like the Model 33.

Lawrence
Nov 14 '05 #8
On Wed, 15 Dec 2004 13:13:34 +0000, Lawrence Kirby
<lk****@netacti ve.co.uk> wrote:
On Wed, 15 Dec 2004 11:31:50 +0000, Chris Croughton wrote:
On 14 Dec 2004 16:43:36 -0800, JeffS
<ja****@yahoo.c om> wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)

Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?


The concepts 'console' and 'cursor' are inherently platform-specific


To a degree but libraries like Curses have shown you have create a pretty
portable programming model for them.


For a limited set of terminals (I don't know of any versions for GUI,
for example, and there are a number of functions of some terminals which
can't be manipulated using curses). It also has to know about what the
terminal type is, if the one actually connected is different frm what it
expects it won't work.
(try positioning a cursor on a Teletype(R) Model 33!).


The fact that you can find environments that don't support this doesn't
invalidate the creation of a portable API for those that do. Such an
interface could simply say "Sorry can't do that" where that is
appropriate. Some programs (well any program) just can't run usefully on
platforms with inadequate functionality, that's true of standard C as it
is.


The point is that the C library is mostly designed around things which
any C implementation can do. A program written to the C standard should
work on most platforms, if it needs to do something else then it becomes
less portable. Adding curses, which is inherently system-specific not
only in its implementation but also in its functionality, would bloat
the spec. with hundreds of functions which a lot of systems can't use
but which still take up space in the namespace.

As it is, I can have a perfectly portable program which has functions
called erase(), flash() etc. with no problem, only if I include the
(non-standard) curses.h do I encounter naming clashes. The C standard
mandates that standard functions must not be redefined.
It is therefore OT for c.l.c (but see below for suggestions).


It is OT because the C language designers chose not to provide such
support in standard C, not because they couldn't have done. Curses exists
despite things like the Model 33.


Well, no, it's orthogonal to the language. The curses library can
theoretically be used from any language on a system it supports (as long
as the calling conventions are compatible), it's a system feature not a
C one. It can also easily have multiple implementations (on my system I
have both curses and ncurses, and just link the appropriate one), and
can be extended without affecting the language standard.

Also, the standard for it is not dependent on the C standards
committees, which would take even more time arguing over it every time
new hardware comes along which needs an additional function.

There is something to be said for decoupling most of the existing C
library from the language, to make the language standard not dependent
on its environment at all...

Chris C
Nov 14 '05 #9
JeffS wrote:
Honest, I scoured the comp.lang.c.faq for this but found nothing. :)
Really?
Is there a library function for placing the cursor position in the
console? Or is it something that can only be done with a platform API
call?

http://www.eskimo.com/~scs/C-faq/q19.4.html


Brian
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4406
by: JP SIngh | last post by:
Thanks to Manohar for writing the basic code for displaying the managers and the employees in a tree like structure. I have adapted the code below but it gives me an error "exception occcured" after the first recursion. Any ideas what can be done to make the following code work. Thanks
2
3039
by: Kamran | last post by:
Hi I have very little experience of C++, nevertheless I have been asked to write a gui using QT/QWT. I know that I should direct the question to the relevant mailing list and I have done that but I think my problem has to do with my lack of understandign of some issues in C++. There is a class in QWT called QwtPicker which allows one to make rubberbands and select part of the drawing canvas, very useful in zooming etc. Function...
1
13171
by: Dan H. | last post by:
Hello, I want to try to retrieve the cursor position x and y relative to the form the cursor is over. The way I am doing it now is: 1. Retrieve the left and top position of the form relative to the desktop 2. Retrieve the desktop cursor position. 3. Take the difference of the forms left and top position. Adjust the desktop cursor position based on this.
5
3001
by: Tina | last post by:
How is it possible to designate a textbox so that when the .aspx page is displayed the cursor is already there so the user can just start typing instead of having to click in the textbox with the mouse first? thanks, T
1
4689
by: Mario Figueiredo | last post by:
Hello everyone, I'm having trouble controlling the cursor position when I make two consecutive calls to the get family of functions. This problem does not happen if there is an output in between. The following code illustrates the problem in a simplified way: #include "curses.h"
0
3235
by: malen | last post by:
Hi all! I'm building mouse movement filter program for Windows and Mac OS X. In Windows I use ctypes.windll.user32.getCursorPos(pointer) and ctypes.windll.user32.setCursorPos(x,y) to get and set the cursor position but I do not know what the library and functions are called in Mac OS X (I'm a complete noob when it comes to Mac :) ) To explain better (I hope) here is the windows code for a test program that forces the mouse to use a...
1
2842
nathj
by: nathj | last post by:
Hi, I'm surrently struggling with something I'm certain should be very simple. I'm working on a new web application that requires every user to login before they do anything else. This means that the first page is a login page. I have produced simple graphic for the login form and I want the controls to sit within this. Unfortunately this is all just local only at the moment and so I can show you the results. The code is as follows:...
2
2516
by: ismailc | last post by:
Hi, I need help please! Onmouseover it calls a function, but onmouseover the image it changes the cursor from default ot busy the whole time. I want it to stay to default. I have set it o default in the div, function & onmouseover but it stil does that <div id="hoverText2" class="main" style="padding: 5px; position: absolute; display: none; width: 200px; cursor : default;"></div>
13
3620
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at this time (in fact, I don't even know if it totally works, I'm still debugging). However, the first problem is that when an error is encountered, I get my alert box, I press ok and then the form is submitted and the new data is entered into the...
0
9881
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9727
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10982
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10706
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10331
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7880
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3160
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.