•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 402,003 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,401 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Views: 4315 | Replies: 7
![]() |
•
•
Join Date: Apr 2007
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
<< split from this thread >>
I am a student in Bogazici University/Turkey. We have a project and I want to change the cursor position but there is a problem. Our teachers are using Microsoft Visual C++ 2005 Express Edition. In this compiler there is no windows.h header. What can I do?
I am a student in Bogazici University/Turkey. We have a project and I want to change the cursor position but there is a problem. Our teachers are using Microsoft Visual C++ 2005 Express Edition. In this compiler there is no windows.h header. What can I do?
•
•
•
•
>Can you please help me on calling interrupts in that standard?
Didn't you already ask that question, or was it someone else?
>By I think, one of the h files can be used for this purpose.
windows.h, and you have to implement the functionality yourself:
#include <windows.h> void gotoxy ( short x, short y ) { COORD coord = {x, y}; SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord ); }
Last edited by ~s.o.s~ : Apr 7th, 2007 at 5:45 am. Reason: Added link to original thread.
•
•
Join Date: Dec 2006
Location: india
Posts: 1,058
Reputation:
Rep Power: 9
Solved Threads: 160
•
•
•
•
I am a student in Bogazici University/Turkey. We have a project and I want to change the cursor position but there is a problem. Our teachers are using Microsoft Visual C++ 2005 Express Edition. In this compiler there is no windows.h header. What can I do?
visual c++ express does not ship with the platform sdk (for which windows.h is the main header). however, you can download and install the platform sdk for free. and you need to set up the visual c++ environment to use it. for clear step-by-step instructions on how to do this, see:
http://msdn.microsoft.com/vstudio/ex...alc/usingpsdk/
Last edited by vijayan121 : Apr 6th, 2007 at 7:18 pm. Reason: typo
It seems that you like to write some console/terminal applications. Please try to understand me now. Standard C doesn't provide any features for that. Yes it's somewhat stupid to be able to write only some command-line programs, for example, while learning C. But C standard library is anyway only a fraction of POSIX, so it makes no sense to be restricted with C standard library. And such console/terminal programs can be written using only standard C and POSIX. We need really two things -- non-canonical input and clear screen. The code below shows how we can set the non-canonical input using termios.h, this code clears screen and prints immediately any character which you enter. Clearing screen is somewhat more tricky, because POSIX doesn't provide any function or control sequence to clear the screen. It provides a command "tput clear" for that though. So the only way to clear screen quickly using only the POSIX features, is to get the control sequence which "tput clear" outputs, and then print it every time to clear screen. The code below gets that control sequence using popen.
And now again, how can we move the cursor. POSIX does not provide any control codes, functions or utilities to move cursor. And if to think about it more deeply, *you do not need to move cursor*, the gotoxy kind of functions for console are somewhat similar to goto functions in c, both seem to be convenient, but would cause a bad programming. It is that whenever we have a user interface, we need windows, consider things like a message box which should pop up. And always when we have windows, there must be a function for every window, which rewrites all its content in any particular moment, because a window may become covered by another window etc. It is the general philosophy, and even not difficult to implement, it's just a matter of approach. And having such function, we would not need to move cursor any more, we just update an area after every change, which is normal, most text editors update screen after every letter you type.
Anyway, writing console applications makes sense only for simple programs, it would make no sense to write a program with complicated user interface without using graphical UIlike GTK. And it is that most people write only simple programs, why really should they then learn things like curses, only to write a simple interactive program.
If you use Windows, depending on your compiler, you may have to use Windows functions for non-canonical input and clearing screen. But when you do even that, it's better to still follow all that, then it would be easy to port your program to pure POSIX and it can easily run on any platform.
And now again, how can we move the cursor. POSIX does not provide any control codes, functions or utilities to move cursor. And if to think about it more deeply, *you do not need to move cursor*, the gotoxy kind of functions for console are somewhat similar to goto functions in c, both seem to be convenient, but would cause a bad programming. It is that whenever we have a user interface, we need windows, consider things like a message box which should pop up. And always when we have windows, there must be a function for every window, which rewrites all its content in any particular moment, because a window may become covered by another window etc. It is the general philosophy, and even not difficult to implement, it's just a matter of approach. And having such function, we would not need to move cursor any more, we just update an area after every change, which is normal, most text editors update screen after every letter you type.
Anyway, writing console applications makes sense only for simple programs, it would make no sense to write a program with complicated user interface without using graphical UIlike GTK. And it is that most people write only simple programs, why really should they then learn things like curses, only to write a simple interactive program.
If you use Windows, depending on your compiler, you may have to use Windows functions for non-canonical input and clearing screen. But when you do even that, it's better to still follow all that, then it would be easy to port your program to pure POSIX and it can easily run on any platform.
#!/usr/bin/tcc -run
#include <stdio.h>
#include <termios.h>
int main ()
{
struct termios ts0, ts1;
char cls [FILENAME_MAX];
FILE *f;
f = popen ("tput clear", "r");
fgets (cls, FILENAME_MAX, f);
pclose (f);
tcgetattr (0, &ts0);
ts1 = ts0;
ts1.c_lflag &= ~ECHO;
ts1.c_lflag &= ~ICANON;
tcsetattr (0, TCSAFLUSH, &ts1);
fputs (cls, stdout);
while (1) putchar (getchar ());
tcsetattr (0, TCSAFLUSH, &ts0);
return 0;
} It depends what you need to do. If you can do it with canonical input, you can just rewrite the screen every time something changes, the problem with this is that it's slow, and is not a good solution when something changes very often, especially on Windows console which is extremely slow. And yes, without cleaning screen it may show some flickering, it's not exactly a good quality, but then for some university tasks it may even be enough, and the program written like that can later be very easily ported. The canonical input is mostly the biggest problem, because many such interactive programs also need some moving around, like for selecting something, and doing that with canonical input is just much too inconvenient. BTW, system ("cls") clears the screen in Windows, but it can only be used when it will not occur very often, and i didn't really try whether the cls command in Windows also sends some control sequence to console, though i doubt that it doesn't.
•
•
•
•
It seems that you like to write some console/terminal applications. Please try to understand me now. Standard C doesn't provide any features for that. Yes it's somewhat stupid to be able to write only some command-line programs, for example, while learning C.
•
•
•
•
But C standard library is anyway only a fraction of POSIX, so it makes no sense to be restricted with C standard library.
•
•
•
•
And such console/terminal programs can be written using only standard C and POSIX. We need really two things -- non-canonical input and clear screen. The code below shows how we can set the non-canonical input using termios.h, this code clears screen and prints immediately any character which you enter.
•
•
•
•
POSIX does not provide any control codes, functions or utilities to move cursor. And if to think about it more deeply, *you do not need to move cursor*, the gotoxy kind of functions for console are somewhat similar to goto functions in c, both seem to be convenient, but would cause a bad programming.

•
•
•
•
It is that whenever we have a user interface, we need windows,
•
•
•
•
Anyway, writing console applications makes sense only for simple programs, it would make no sense to write a program with complicated user interface without using graphical UIlike GTK. And it is that most people write only simple programs, why really should they then learn things like curses, only to write a simple interactive program.
•
•
•
•
I add this code. But Visual C++ Express Edition doesn't have terminos.h too. where can i get this? Maybe in SDK?
There is no standard way to use cursor control in C. If it's a requirement, your instructor will explain how he wants it done.
Age is unimportant -- except in cheese
It seems that what concerns the programming, there are so many opinions that it's even not worth to discuss. termios.h is a POSIX header, and POSIX is standard, the only standard of an operating system, and even Microsoft has some POSIX kit, even Windows somewhat follows that standard. Windows are a programming concept, not only graphical windows what we see on the screen. But in Windows, it's really likely the only way to get any kit which has windows.h, and use non-canonical input and moving cursor from there. windows.h is about windows api, it's not any standard though. But of course it's necessary to ask what kit the instructor has.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- How get the Cursor Position (Shell Scripting)
- Setting Up The Cursor Position (C++)
- How to get cursor position using c++ in Unix OS? (C++)
Other Threads in the C++ Forum
- Previous Thread: Own getchar function
- Next Thread: string array size



Linear Mode