如何在C中创建菜单 [英] How do I create a menu in C

查看:119
本文介绍了如何在C中创建菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎我需要使用do while循环来完成它,但我真的不明白如何让它工作。我已经弄清楚如何为菜单创建功能,但不知道如何创建菜单或如何进行初始扫描,扫描到两个功能。



样本运行应该看起来像



输入短信:唱一首歌。



可供选择:

1.显示每个字母的出现次数

2.打印单词数量消息

3.退出



输入您选择的号码:

解决方案

< blockquote>一个简单的菜单只是一个打印列表,然后是输入命令,然后是一些选择。类似于:

  int  choice =  -   1 ; 
执行
{
printf( 输入以下选项:\ n);
printf( 0.Quit\\\
);
printf( 1.输入字词:\ n);
printf( 2.计算单词:\ n);
printf( 3.翻译句子:\ n);
printf( 4 ...:\ n); // etc ...
scanf( %d,& choice);
if (choice == 0
断裂;
switch (选择)
{
case 1
// 做一些工作
break ;
// etc
default
printf( 错误的选择:%d,再试一次'\\ n,choice);
break ;
}
} while 1 );


It seems like I need to do it with do while loops, but I don't really understand how to make it work yet. I've figured out how to create the functions for the menu but not how to create the menu or how to have the initial scan, scan into both functions.

A sample run is supposed to look like

Enter a text message: Sing a song.

Available choices:
1. Display number of occurrences of each letter
2. Print number of words in message
3. Quit

Enter the number of your choice:

解决方案

A simple menu would be just a printed list, followed by an input command, and then some choices. Something like:

int choice = -1;
do
{
    printf("Enter choice from the following:\n");
    printf("0. Quit\n");
    printf("1. Enter words:\n");
    printf("2. Count the words:\n");
    printf("3. Reverse the sentence:\n");
    printf("4 ...:\n"); // etc ...
    scanf("%d", &choice);
    if (choice == 0)
        break;
    switch (choice)
    {
    case 1:
        // do some work
        break;
    // etc
    default:
        printf("Bad choice: %d, try again\n", choice);
        break;
    }
} while (1);


这篇关于如何在C中创建菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆