|
因本人不再做技术,
这个blog将不再连载技术文章,
只作为心情点滴的记录,
想学技术的请绕道,谢谢!
联系方式:
feiyu_lili@163.com |
时 间 记 忆 |
« | July 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | |
|
blog名称:飞鱼的成长 日志总数:120 评论数量:488 留言数量:18 访问次数:1044006 建立时间:2006年2月27日 |
 | | | |
|
|
类似的例子:
/* menuette.c -- menu techniques */
#include <stdio.h>
#include "stdafx.h"
char get_choice(void);
char get_first(void);
int get_int(void);
void count(void);
int _tmain(int argc, _TCHAR* argv[])
{
int choice;
void count(void);
while ( (choice = get_choice()) != 'q')
{
switch (choice)
{
case 'a' : printf("Buy low, sell high.\n");
break;
case 'b' : putchar('\a'); /* ANSI */
break;
case 'c' : count();
break;
default : printf("Program error!\n");
break;
}
}
printf("Bye.\n");
return 0;
}
void count(void)
{
int n,i;
printf("Count how far? Enter an integer:\n");
n = get_int();
for (i = 1; i <= n; i++)
printf("%d\n", i);
while ( getchar() != '\n')
continue;
}
char get_choice(void)
{
int ch;
printf("Enter the letter of your choice:\n");
printf("a. advice b. bell\n");
printf("c. count q. quit\n");
ch = get_first();
while ( (ch < 'a' || ch > 'c') && ch != 'q')
{
printf("Please respond with a, b, c, or q.\n");
ch = get_first(); //去处‘\n’的影响
}
return ch;
}
char get_first(void)
{
int ch;
ch = getchar();
while (getchar() != '\n')
continue;
return ch;
}
int get_int(void)
{
int input;
char ch;
while (scanf("%d", &input) != 1)
{
while ((ch = getchar()) != '\n')
putchar(ch); // dispose of bad input
printf(" is not an integer.\nPlease enter an ");
printf("integer value, such as 25, -178, or 3: ");
}
return input;
}
|
|
| | |
|