User Name Password Register
DaniWeb IT Discussion Community
All
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
Reply
Join Date: Apr 2007
Posts: 2
Reputation: tasomaniac is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tasomaniac tasomaniac is offline Offline
Newbie Poster

Re: Setting Up The Cursor Position

  #1  
Apr 6th, 2007
<< 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?


Originally Posted by Narue View Post
>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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Posts: 19
Reputation: hkBattousai is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
hkBattousai's Avatar
hkBattousai hkBattousai is offline Offline
Newbie Poster

Re: Setting Up The Cursor Position

  #2  
Apr 6th, 2007
There is no way VS C++ doesn't contain windows.h in its include folder; when the pigs fly...

You had better search for that file using windows' search tool or using something like Google Desktop.
Reply With Quote  
Join Date: Dec 2006
Location: india
Posts: 1,058
Reputation: vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light vijayan121 is a glorious beacon of light 
Rep Power: 9
Solved Threads: 160
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Setting Up The Cursor Position

  #3  
Apr 6th, 2007
Originally Posted by tasomaniac View Post
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
Reply With Quote  
Join Date: Mar 2005
Posts: 154
Reputation: TkTkorrovi is on a distinguished road 
Rep Power: 4
Solved Threads: 11
TkTkorrovi's Avatar
TkTkorrovi TkTkorrovi is offline Offline
Junior Poster

Re: Setting Up The Cursor Position

  #4  
Apr 6th, 2007
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.
#!/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;
}
Reply With Quote  
Join Date: Apr 2007
Posts: 2
Reputation: tasomaniac is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tasomaniac tasomaniac is offline Offline
Newbie Poster

Re: Setting Up The Cursor Position

  #5  
Apr 7th, 2007
I add this code. But Visual C++ Express Edition doesn't have terminos.h too. where can i get this? Maybe in SDK?
Reply With Quote  
Join Date: Mar 2005
Posts: 154
Reputation: TkTkorrovi is on a distinguished road 
Rep Power: 4
Solved Threads: 11
TkTkorrovi's Avatar
TkTkorrovi TkTkorrovi is offline Offline
Junior Poster

Re: Setting Cursor position

  #6  
Apr 7th, 2007
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.
Reply With Quote  
Join Date: May 2006
Posts: 2,700
Reputation: WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold WaltP is a splendid one to behold 
Rep Power: 14
Solved Threads: 219
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Maven

Re: Setting Cursor position

  #7  
Apr 8th, 2007
Originally Posted by TkTkorrovi View Post
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 it's even stupider to try to learn C and a very non-standard library like POSIX.

Originally Posted by TkTkorrovi View Post
But C standard library is anyway only a fraction of POSIX, so it makes no sense to be restricted with C standard library.
Makes total sense. If learning C, you learn C that can be used everywhere. Learn C and POSIX, now you can only write code that has POSIX, and most jobs you are likely to get won't have it.

Originally Posted by TkTkorrovi View Post
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.
So now we not only add a non-standard library like POSIX, but now another non-standard header the is available only on Linux. Really helps on Windows... :rolleyes:

Originally Posted by TkTkorrovi View Post
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.
As is POSIX

Originally Posted by TkTkorrovi View Post
It is that whenever we have a user interface, we need windows,
I've been writing code long before any windowing even existed. It is not necessary. Windowing is difficult to do properly, and when learning C it is best to concentrate on C, not on overly bloated windowing.

Originally Posted by TkTkorrovi View Post
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.
To paraphrase what I said before, extremely complex programs have been written long before any GUI existed. It all depends on what you want. Cute graphics and overblown executable or something that works well so you can concentrate on learning what you need to learn.

Originally Posted by tasomaniac View Post
I add this code. But Visual C++ Express Edition doesn't have terminos.h too. where can i get this? Maybe in SDK?
That's because Windows doesn't have terminos.h. It's a Unix thing.

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
Reply With Quote  
Join Date: Mar 2005
Posts: 154
Reputation: TkTkorrovi is on a distinguished road 
Rep Power: 4
Solved Threads: 11
TkTkorrovi's Avatar
TkTkorrovi TkTkorrovi is offline Offline
Junior Poster

Re: Setting Cursor position

  #8  
Apr 8th, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 9:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC