Jump to content
  • Advertisement
Sign in to follow this  
Ned_K

Two windows console programming questions (C/Win32)

This topic is 3816 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Question 1: How can I run console command line parameters/commands directly from within a C program without it being messy? Question 2: What is the Win32 approach to single character input? I want to grab a single character in a console without an "enter" keypress from the user and then move on. I'm having a heck of a time finding exactly what I need here. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
1) It'll always be messy. You just need to figure out which kind of mess you want.
2) Most compilers for Windows support a header called conio.h. In that header will usually be a function called getch() or _getch() that sounds like what you want.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
2) Most compilers for Windows support a header called conio.h. In that header will usually be a function called getch() or _getch() that sounds like what you want.


Great, thanks. Looking into that further now.

Quote:
1) It'll always be messy. You just need to figure out which kind of mess you want.

Can you point me to a discussion of it or tutorial? I keep googling and it always gives me something unrelated since the search terms have so many other topics in common and so far msdn hasn't had anything explicit that I have found.


Share this post


Link to post
Share on other sites
Look up the system(), ShellExecute() and CreateProcess() functions. Or if you're feeling especially masochistic execl(), execle(), execlp() and execlpe().

Share this post


Link to post
Share on other sites
I never recommend using conio.h . It’s not like a third party library. It’s a compiler dependent library, with absolutely no standardisation. Instead, you should use the Win32 API to implement the equivalent of getch.

See http://msdn2.microsoft.com/en-us/library/ms683462(VS.85).aspx (MSDN page) and http://www.mser.net/microsoft-developer-network/28/visual-c++-programming-281357.shtm (3rd reply).

Share this post


Link to post
Share on other sites
Quote:
How would exec* work in Windows? I don't seem to remember being able to fork a process.
exec wouldn’t work in Windows. Can’t fork a process in Windows either. Sorry.

But it’s probably worth keeping in mind the fork/exec method on *NIX systems.

Share this post


Link to post
Share on other sites
Quote:
Original post by oler1s
exec wouldn’t work in Windows.

It's available via the MSVC CRT implementation, which means it can be used by programs compiled with MSVC or compilers that utilize the MSVC runtime like MinGW. See _exec on MSDN. Other compiler vendors like Borland support it as well.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!