473,413 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

making a VERY simple menu

Good evening,

I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.

thanks in advance

Tim

Jan 24 '06 #1
22 2518
tr*****@gmail.com wrote:
I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.


Print options using printf(). Input the user's choice using scanf(). Don't
forget to check for errors in the input part. Repeat until you have a
valid choice.

Just try it, it's really simple.

Uli

Jan 24 '06 #2
tr*****@gmail.com wrote:
Good evening,

I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.


Depends. If you want fancy stuff using arrow keys etc.,
then you are wrong here as we discuss only standard C.
A newsgroup discussing DOS will probably be able to point
you in the right direction.
If you stick with standard C, you can do something along
the lines
do {
/* Output options */
fflush(stdout);
/* Read in the reply, do not use *scanf() see clc faq */
/* variant a) safe user choice */
} while (!validchoice);
/* a) dispatch according to choice*/
or
do {
/* Output options */
fflush(stdout);
/* Read in the reply, do not use *scanf() see clc faq */
/* variant b) dispatch according to non-exit choice */
} while (!exitmenu);

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Jan 24 '06 #3
Ulrich Eckhardt wrote:
tr*****@gmail.com wrote:
I was thinking about making a very simple DOS based (console) menu
for a project that i am working on, but I have no idea where to start
for something like this. Does anyone have any resources they could
point me to or shed some light on what it is that you do exactly.
Like I said, I don't want a real complicated menu, just a title and
about three options. I will add more stuff once I know what it is
that I am doing.
Print options using printf(). Input the user's choice using scanf().
Don't forget to check for errors in the input part. Repeat until you
have a valid choice.


I'd suggest to use printf()/fgets()/sscanf() instead, just to be on the
safe side (NOT gets()), and /do/ check for invalid input.
Just try it, it's really simple.


I concur.

Cheers

Vladimir

--
You know you've landed gear-up when it takes full power to taxi.

Jan 24 '06 #4
Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?

Tim

Jan 24 '06 #5
"Tim Ricard" wrote:
Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?


No, function keys and their mere existence are outside the scope of standard
C.
Jan 24 '06 #6
Please quote what you reply to...

Tim Ricard wrote:
Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?

Tim


Standard C does not know anytrhing about the "screen". ;-)

What I'd suggest, if you wanted 100% standard C and portability, is to
simulate celaring the screen by outputing /many/ blank lines when
re-drawing the menu. Scrolling may just send the old menu off the
screen. You'll never know how many is enough for any given machine, but
at least the old menu will be far away from the new.

Otherwise, ask about your specific platform in appropriate group. You
mention DOS, so comp.os.msdos.programmer may be the right place.

Cheers

Vladimir

Jan 24 '06 #7
Tim Ricard wrote:

Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?


It's not. There is no mention of 'screen' in the C standard.

Please include adequate context. See below for how on the broken
google interface to usenet.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>

Jan 24 '06 #8
Tim Ricard wrote:
Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?


You can't do it in standard C not can you portably detect the F3 key, so
you will have to go to a DOS group for this.

By the way, asking here if something is possible in standard C is
perfectly reasonable even when the answer turns out to be no.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Jan 24 '06 #9
"Vladimir S. Oka" <no****@btopenworld.com> writes:
[...]
Standard C does not know anytrhing about the "screen". ;-)

What I'd suggest, if you wanted 100% standard C and portability, is to
simulate celaring the screen by outputing /many/ blank lines when
re-drawing the menu. Scrolling may just send the old menu off the
screen. You'll never know how many is enough for any given machine, but
at least the old menu will be far away from the new.


Sure, but I think this is one of the cases where 100% standard C just
isn't worth the effort. If you really need to clear the screen, I'd
say you're better off finding out how to do it on each system you want
to support and writing a clear_screen function with however many
#ifdefs you need. (You can even resort to printing a bunch of blank
lines if all the #ifdefs fail.) The result is going to look a *lot*
better.

Then again, it's not likely that clearing the screen is going to be
the only system-specific think you want to do. If you want to be able
to move the cursor to an arbitrary position on the screen, for
example, you'll need to use some more system-specific code, which is
likely to become a fairly large part of your program.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 24 '06 #10
Tim Ricard <tr*****@gmail.com> wrote in article
<11**********************@g44g2000cwa.googlegroups .com>...
Thanks for the help. Okay, so just one question then, just so I know if
this is a standard C question or not. What if I want some items to be
static on the screen (like at the bottom have "press F3 for help"
etc.)? Is this a standard C question or more specific to a DOS C group?

Tim


I've often had good luck at:

comp.os.msdos.programmer

That's where I go when I have questions on DOS console applications,
function key access, etc.

Good luck!

Brian Dude
Jan 24 '06 #11
tr*****@gmail.com a écrit :
I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.


It's quite a simple algorithm:

DO
printout the options
entry an option
test the entry
execute the corresponding action
UNTIL end

do your best and post the code if you are stuck.

--
A+

Emmanuel Delahaye
Jan 24 '06 #12
Keith Thompson <ks***@mib.org> writes:
[...]
Then again, it's not likely that clearing the screen is going to be
the only system-specific think you want to do. If you want to be able
to move the cursor to an arbitrary position on the screen, for
example, you'll need to use some more system-specific code, which is
likely to become a fairly large part of your program.


And if clearing the screen *is* the only system-specific thing you
want to do, pleaes reconsider whether you really need to do that.
Clearing my screen for a full-screen text editor is ok; erasing what
might be important information just so your program's prompt can be at
the top of a blank screen is rude.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 24 '06 #13
Keith Thompson wrote:
Keith Thompson <ks***@mib.org> writes:
[...]
Then again, it's not likely that clearing the screen is going to be
the only system-specific think you want to do. If you want to be able
to move the cursor to an arbitrary position on the screen, for
example, you'll need to use some more system-specific code, which is
likely to become a fairly large part of your program.

And if clearing the screen *is* the only system-specific thing you
want to do, pleaes reconsider whether you really need to do that.
Clearing my screen for a full-screen text editor is ok; erasing what
might be important information just so your program's prompt can be at
the top of a blank screen is rude.


After a couple of conio.h episodes several years ago, I gave up on CLI
stuff altogether. Now I think to take it up again 'portably' using
curses. Theoretically the same simple menu could run on Unix, Sun and
DOS as well. Although curses is not Standard it is ubiquitous. Is it
portable?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Jan 24 '06 #14
tr*****@gmail.com wrote:
Good evening,

I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.


Here is a simple example of a menu in Standard C:

#include <stdio.h>
#include <stdlib.h>

int main (void) {
int long c = 0;
char buf[80];
puts("Select an option");
puts("1 First option");
puts("2 Second option");
puts("3 Third option");
while (fgets(buf, 100, stdin) != NULL) {
c = strtol(buf, NULL, 10);
switch (c) {
case 1: case 2: case 3:
printf("You selected option %ld\n", c);
break;
default:
puts("Invalid option");
break;
}
}
return 0;
}

The only case not explicitly handled is when a user inputs n characters
at a time where n is greater than 79, in this case the loop will run
n/79+1 times. If this is not what you would like you can drain the
input buffer after each call to fgets (there is no standard function
specifically for this purpose) or use some scanf magic. Also note that
if someone enters "2h", this will behave as if the user entered "2".

If you want to do anything fancy like cursor placement, unbuffered
non-blocking i/o, colors, etc. you will need to step outside Standard
C. In that case you may want to check out ncurses (which is off-topic
here so if you have questions about it ask elsewhere).

Robert Gamble

Jan 24 '06 #15
Robert Gamble wrote:
tr*****@gmail.com wrote:
Good evening,

I was thinking about making a very simple DOS based (console) menu for
a project that i am working on, but I have no idea where to start for
something like this. Does anyone have any resources they could point me
to or shed some light on what it is that you do exactly. Like I said, I
don't want a real complicated menu, just a title and about three
options. I will add more stuff once I know what it is that I am doing.


Here is a simple example of a menu in Standard C:

#include <stdio.h>
#include <stdlib.h>

int main (void) {
int long c = 0;
char buf[80];
puts("Select an option");
puts("1 First option");
puts("2 Second option");
puts("3 Third option");
while (fgets(buf, 100, stdin) != NULL) {


that line should be:

while (fgets(buf, 80, stdin) != NULL) {

you always notice these things right *after* you hit submit...

Robert Gamble

Jan 24 '06 #16
Joe Wright <jo********@comcast.net> writes:
[...]
After a couple of conio.h episodes several years ago, I gave up on CLI
stuff altogether. Now I think to take it up again 'portably' using
curses. Theoretically the same simple menu could run on Unix, Sun and
DOS as well. Although curses is not Standard it is ubiquitous. Is it
portable?


"Is it portable?" is not a yes/no question.

There are multiple systems on which some version of curses is
available. There are undoubtedly systems on which it's not available.
I probably know less than you do about which systems fall into each
category (I wasn't aware of a curses implementation for DOS), and the
question isn't particularly topical anyway.

The real question, I suppose, is whether it's portable enough for your
purposes, i.e., whether curses is supported on all the systems you'd
want your software to run on. I haven't a clue what the answer is.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Jan 25 '06 #17

"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Robert Gamble wrote:
tr*****@gmail.com wrote:
> Good evening,
>
> I was thinking about making a very simple DOS based (console) menu for
> a project that i am working on, but I have no idea where to start for
> something like this. Does anyone have any resources they could point me
> to or shed some light on what it is that you do exactly. Like I said, I
> don't want a real complicated menu, just a title and about three
> options. I will add more stuff once I know what it is that I am doing.
Here is a simple example of a menu in Standard C:

#include <stdio.h>
#include <stdlib.h>

int main (void) {
int long c = 0;
char buf[80];
puts("Select an option");
puts("1 First option");
puts("2 Second option");
puts("3 Third option");
while (fgets(buf, 100, stdin) != NULL) {


that line should be:

while (fgets(buf, 80, stdin) != NULL) {


No, I'd personally prefer:
while(fgets(buf, sizeof buf, stdin) != NULL) {

I think you've made a pretty good case as to why ;-)
you always notice these things right *after* you hit submit...

I know the feeling...
Jan 25 '06 #18
Mark B wrote:
"Robert Gamble" <rg*******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Robert Gamble wrote:
tr*****@gmail.com wrote:
> Good evening,
>
> I was thinking about making a very simple DOS based (console) menu for
> a project that i am working on, but I have no idea where to start for
> something like this. Does anyone have any resources they could point me
> to or shed some light on what it is that you do exactly. Like I said, I
> don't want a real complicated menu, just a title and about three
> options. I will add more stuff once I know what it is that I am doing.

Here is a simple example of a menu in Standard C:

#include <stdio.h>
#include <stdlib.h>

int main (void) {
int long c = 0;
char buf[80];
puts("Select an option");
puts("1 First option");
puts("2 Second option");
puts("3 Third option");
while (fgets(buf, 100, stdin) != NULL) {


that line should be:

while (fgets(buf, 80, stdin) != NULL) {


No, I'd personally prefer:
while(fgets(buf, sizeof buf, stdin) != NULL) {

I think you've made a pretty good case as to why ;-)


In production code I might use a macro or variable for the size of the
buffer. The only reason I wouldn't go with your suggestion is because
it fails if buf ever becomes a pointer to dynamically allocated memory,
but that's just me.

Robert Gamble

Jan 25 '06 #19
Robert Gamble a écrit :
Here is a simple example of a menu in Standard C:

char buf[80]; <...> while (fgets(buf, 100, stdin) != NULL) {


You're kidding, aren't you ?

--
A+

Emmanuel Delahaye
Jan 25 '06 #20
Emmanuel Delahaye wrote:
Robert Gamble a écrit :
Here is a simple example of a menu in Standard C:

char buf[80];

<...>
while (fgets(buf, 100, stdin) != NULL) {


You're kidding, aren't you ?


I changed the size before I posted and somehow the change wasn't
propagated to the rest of the program ;) I corrected myself five
minutes after I posted, I guess your server didn't pick up that post.

Robert Gamble

Jan 25 '06 #21
Thank you sir :).

Tim

Jan 26 '06 #22
I guess it helps to quote who helped me ;):
I've often had good luck at:

comp.os.msdos.programmer

That's where I go when I have questions on DOS console applications,
function key access, etc.

Good luck!

Brian Dude


So once again, thank you.

Tim

Jan 26 '06 #23

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

Similar topics

5
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. ...
1
by: John Doe | last post by:
I've made this simple menu using a javascript : http://larsandre.mine.nu/menu.htm If I select one of the menu items the submenu appears just fine, my only problem is that If I point the mouse...
10
by: Gernot Frisch | last post by:
Hi, I have found some menu functions. It works quite well, but how can I replace it with a simple <a href> if javascript is turned off? I reduced my code to:...
7
by: Sens Fan Happy In OH | last post by:
I'm having majour issues with FrontPage 2K and a webpage that I am having to create from scratch based on someone else's prior work. I hope someone can look at the source code for the page in...
3
by: bardo | last post by:
I am running into the following problem would like to know if this a bug or me doing something wrong. Using C# with visual studios 2003. I make a form and add a mainMenu Control. Now I type in...
6
by: Bob | last post by:
I'd like to be able to do three things with the context menu 1. change the width 2. change the borderstyle to none 3. change the back color I don't think it's possible, so what's the best way...
5
by: le007 | last post by:
:) Hey All, I've recently tried my hand with CSS. I know a good bit of html and thats more or less it. I've moved back to Ireland from Australia now and I'm trying to put a site together to keep...
6
by: BoscoPippa | last post by:
I'm an extreme newbie at C++ and am working on my final project for my beginner course. I have an issue, though, and I'm hoping I can get a nudge in the right direction. The program functions via...
1
by: HACKhalo2 | last post by:
Hi. I'm helping a friend of mine develop an online game, which is currently outdated. The person making skins for the site came up with a cool looking NavBar (found at...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.