#include <stdio.h>
char get_choice(void);
char get_first(void);
int get_int(void);
void count(void);
int main(void){
int choice;
void count(void);
while ( (choice = get_choice()) != 'q')
{
switch (choice)
{
case 'a' : printf(a.\n);
break;
case 'b' : putchar('b'); /* ANSI */
break;
case 'c' : count();
break;
default : printf(error!\n);
break;
}
}
printf(Bye.\n);
return 0;
}
void count(void)
{
int n,i;
printf(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:\n);
printf(a. append b. output\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();
}
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.\n);
}
return input;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。