Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 16-12-2007, 07:33 PM   #1 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Alternate to some imp. "conio.h" functions


Guys I want some alternative to getch(), gotoxy(), kbhit(), _setcursortype(), etc. So either recommend me a alternative or help me developing a function of similar kind

Suppose for the program:
Code:
int main()
{
int i=0;
char a[]="Help Me! ",ch;
do
{
ch=getch();
printf("%c",a[i%9]);
i++;
}while(ch!=27); // 27 means ESC
return 0;
}
How will you write the program in ANSI C so that the output program is same/similar.

NOTE: I don't want getch() for pausing between the program .. But for trapping a character.
For pausing I can very well use system("Pause")
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 16-12-2007, 07:50 PM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

getch() is system dependent stuff. To code it would also require usage of system APIs for keyboard input, and so on. This would obviously make it non portable since the way of taking a keyboard input varies with the platform.

Same goes for the rest I think. Most of them are already built for you by the compiler using Windows/DOS APIs, so that you don't have to do the task.

In Linux, there's ncurses/curses libraries which contains getch() and functions similar to the above. But that obviously makes it *nix-dependent, so there we are. Hardware dependency would probably make it non standard?

But hey, your code need not be 'standard' always. Its a developer's choice if he wishes to make code standard and portable (mostly a good thing to do), or dependent (easier using the available compiler methods).

So in short, some functions weren't added to standard C/C++ since the methods of their execution varied across platform (Like the unbuffered getch() input). You got to resort to local libraries for them.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 16-12-2007, 07:50 PM   #3 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Alternate to some imp. "conio.h" functions

http://www.gidnetwork.com/b-61.html

system("PAUSE") isn't standard either. Use getchar() instead (or cin.get() in c++).

Edit:Beaten...
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 16-12-2007, 07:56 PM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

Your link's much better though
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 16-12-2007, 08:16 PM   #5 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Alternate to some imp. "conio.h" functions

Tried both cin.get() and getchar() but the output is not what I actually want..See what my program does is displays array elements one by one irrespective of whatever you type and ends simultaneously when Esc is pressed,
But both the above mentioned functions echoes whatever we type and displays the string after we press Return key.

And sorry guys for starting a new thread ... Because until now I was not knowing about this thread
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 16-12-2007, 08:28 PM   #6 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

The fact is, none of todays applications do such a thing. What application asks the user to enter a key to continue these days? DOS is hardly used. Once you get to GUI programming, you won't look for things like these.

Why would you ask the user to keep hitting a key to show information like that? Isn't showing them all and exiting the right thing to do cause the program has no other aim?

You can't hide the echo on some platforms, so there's no way a getch() can be implemented on it.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 16-12-2007, 08:56 PM   #7 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Alternate to some imp. "conio.h" functions

^^
This program is just for explaining my purpose..Like in vim editor when you press 'x' instead of echoing it, it deletes the current character.
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 16-12-2007, 08:57 PM   #8 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

ncurses/curses, as I already told above, contains getch() and some other stuff.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 16-12-2007, 09:01 PM   #9 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Alternate to some imp. "conio.h" functions

Ok I will try ncurses/curses but I wanted something which is strictly based on ANSI C
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 16-12-2007, 09:05 PM   #10 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

How can platform dependent stuff be part of standard code?
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 16-12-2007, 09:30 PM   #11 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Alternate to some imp. "conio.h" functions

Come on, Even the most basic password based programs in *nix systems this kind of function (not getch ofcourse ) .. Just citing examples..
u press your password "abc!@!@!" but screen displays '*' with each character instead of showing the original character itself or shows nothing at all


And tried ncurses 5.6 .. but still the program is not able to stop character from echoing
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/

Last edited by anantkhaitan; 16-12-2007 at 09:48 PM.
anantkhaitan is offline  
Old 16-12-2007, 10:18 PM   #12 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

*nix doesn't show passwords with a *. It doesn't let it echo at all, right?

But I've seen examples of ncurses using echo(), noecho() functions and they worked fine here too!

Try this:
Code:
#include <ncurses.h>

int main()
{    
    initscr();
    printw("No Echo, Hit 3 keys.");
    refresh();  
    noecho();
    getch();
    getch();
    getch();
    endwin();

    return 0;
}
Quote:
Originally Posted by anantkhaitan
Come on, Even the most basic password based programs in *nix systems this kind of function (not getch ofcourse ) .. Just citing examples..
u press your password "abc!@!@!" but screen displays '*' with each character instead of showing the original character itself or shows nothing at all


And tried ncurses 5.6 .. but still the program is not able to stop character from echoing
You aren't getting my point. Though all platforms have a method of masking/whatever, the implementation is not the same in each. The OS handles this thing, and thus it varies! So they CANT include it as a standard function, can they?
__________________
Harsh J
www.harshj.com

Last edited by QwertyManiac; 16-12-2007 at 10:20 PM. Reason: Automerged Doublepost
QwertyManiac is offline  
Old 16-12-2007, 10:35 PM   #13 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Default Re: Alternate to some imp. "conio.h" functions

Finally .. this noecho() function has done its job.. A very big THANKS to you..
but now if I want to enable the echo effect again, How will I do it??
Plz get me a echo() function ...

Try compiling this:
Code:
#include<ncurses.h>
int main()
{
int i=0;
char a[]="Help Me! ",ch;
initscr();
do
{
noecho();
ch=getch();
printf("%c",a[i%9]);
i++;
}while(ch!=27); // 27 means ESC
return 0;
}
Pleaseeee...
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 16-12-2007, 10:38 PM   #14 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

Use echo() to turn it back on.

RTF(ull)M

Code:
#include <ncurses.h>

int main()
{    
    initscr();            
    printw("No Echo, Hit 2 keys. Echo, Hit another 2 keys.");    
    refresh();            
    noecho();
    getch();
    getch();
    echo();
    getch();
    getch();            
    endwin();

    return 0;
}
printf is not for ncurses ... use printw. This one works fine.
Code:
#include<ncurses.h>

int main()
{
    int i=0;
    char a[]="Help Me! ",ch;
    initscr();
    
    do
    {
        noecho();
        ch=getch();
        printw("%c",a[i%9]);
        i++;
    }while(ch!=27); // 27 means ESC
    
    endwin();
    return 0;
}
__________________
Harsh J
www.harshj.com

Last edited by QwertyManiac; 16-12-2007 at 10:58 PM.
QwertyManiac is offline  
Old 16-12-2007, 11:42 PM   #15 (permalink)
Burning Bright
 
anantkhaitan's Avatar
 
Join Date: May 2006
Location: NIT, Bhopal
Posts: 266
Thumbs up Alternate to some imp. "conio.h" functions

Superb man.. thanks for that..Its finally working.. thanks for every help.. I am so happy..
now you must be knowing what program I was talking about.... thanks again...
__________________
..::Fedora ::.. Freedom + Infinity + Speech
Registered Linux User #447318

GNUger was here.... Grrr....

Maah! Blog
http://brightedges.blogspot.com/
anantkhaitan is offline  
Old 17-12-2007, 12:54 AM   #16 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Alternate to some imp. "conio.h" functions

I knew what your program did already, I was just pointing out, and still do, about how un-useful it is to make such stuff up. TUI's mostly a thing of past now.

Though it is faster to use than GUI sometimes, it just doesn't get its needed popularity.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
NEW VIRUS GIVING MESSAGE:"Can not find script file"WIN32.DLL.dll.vbs" ". mdp Software Q&A 5 02-10-2007 02:11 PM
VISTA TUTORIAL: Add "Hide File Names" Option in "View" Menu of Folders Vishal Gupta Tutorials 7 27-06-2007 10:46 PM
hiding the "download" status "dialog box" keves2002 Internet & WWW 19 08-09-2006 12:28 AM
"INF Error", VGA Driver "Missing" Installing ATI Catalyst Drivers CannedLizard Hardware Q&A 4 29-07-2006 12:47 AM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:45 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2