c语言编写函数菜单 c语言怎么写菜单
怎样用C语言编写菜单?
程序如下:
成都创新互联公司服务项目包括余杭网站建设、余杭网站制作、余杭网页制作以及余杭网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,余杭网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到余杭省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
#includestdio.h
#includestring.h
intMENU_Print(ints32QuerNum)
{
switch(s32QuerNum)
{
case1:
printf(\"您选择的题目如下:\");
printf(\"1、以下可以正确表示标识符的是:()\");
printf(\"A、Data,Double\");
printf(\"B、case,Big\");
printf(\"C、2011A,hi_ok\");
printf(\"D、_2011,year-month-data\");
break;
case2:
printf(\"您选择的题目如下:\");
printf(\"2、以下运算符优先级最低的是:()\");
printf(\"A、?:\");
printf(\"B、++\");
printf(\"C、\");
printf(\"D、+=\");
break;
case3:
printf(\"您选择的题目如下:\");
printf(\"2、以下选项中不能正确赋值的是:()\");
printf(\"A、chars[20];s=\"ABCDE\"\");
printf(\"B、chars[]=\"ABCDE\"\");
printf(\"C、chars[20]={\"ABCDE\"}\");
printf(\"D、chars[20]={'A','B','C'}\");
break;
default:
break;
}
return0;
}
intmain()
{
ints32ChooseNum=0;
while(1)
{
printf(\"题号范围为1-3,请输入题号:\");
scanf(\"%d
C语言编程做一个简单的菜单
#include stdio.h
#include stdlib.h
void menu() //菜单绘制
{
printf("---------------------------------------\n");
printf("\t\t 0.退出\n");
printf("\t\t 1.录入信息\n");
printf("\t\t 2.查找信息\n");
printf("\t\t 3.删除信息\n");
printf("\t\t 4.浏览信息\n");
printf("\t\t 5.有其他疑问找群主")
printf("\t\t 6.C++8群: 491994603")
printf("---------------------------------------\n");
}
void keyDown() //按键处理
{
int choice;
scanf("%d", choice);
switch (choice)
{
case 0:
printf("退出程序\n");
Sleep(2000);
return 0;
case 1:
//调用菜单1实现函数
break;
case 2:
//调用菜单2实现函数
break;
case 3:
//调用菜单3实现函数
break;
case 4:
//调用菜单4实现函数
break;
default:
printf("输入错误\n");
}
system("pause");
return 0;
}
int main()
{
while(1)
{
menu();
keyDown();
system("cls");
}
return 0;
}
怎样用C语言编写菜单
对于窗口组件菜单,需要根据不同平台,通过图形编程接口,进行菜单的编制。
例程:
#includestdio.h
#includegraphics.h
#includeconio.h
void main()
{
char str;
int i,k,choice=1;
int gd=DETECT,gm;
initgraph(gd,gm," ");
setbkcolor(2);
settextstyle(3,0,3);
outtextxy(140,120,"A. The Mock Clock.");
outtextxy(140,150,"B. The Digital Clock.");
outtextxy(140,180,"C. Exit.");
setlinestyle(0,0,3);
rectangle(170,115,370,145);
/*按上下键选择所需选项*/
for(i=1;i=100;i++)
{
str=getch();
if(str==72)
{
--choice;
if(choice==0)choice=3;
}
if(str==80)
{
++choice;
if(choice==4)choice=1;
}
if(str==13)break; /*按回车键确认*/
/*画图做菜单*/
cleardevice();
switch(choice)
{ case 1: setlinestyle(0,0,3);
rectangle(170,115,400,145);
settextstyle(3,0,3);
outtextxy(140,120,"A. The Mock Clock.");
settextstyle(3,0,3);
outtextxy(140,150,"B. The Digital Clock.");
outtextxy(140,180,"C. Exit.");
break;
case 2: setlinestyle(0,0,3);
rectangle(170,145,400,175);
settextstyle(3,0,3);
outtextxy(140,120,"A. The Mock Clock.");
settextstyle(3,0,3);
outtextxy(140,150,"B. The Digital Clock.");
settextstyle(3,0,3);
outtextxy(140,180,"C. Exit.");
break;
case 3: settextstyle(3,0,3);
outtextxy(140,120,"A. The Mock Clock.");
outtextxy(140,150,"B. The Digital Clock.");
settextstyle(3,0,3);
outtextxy(140,180,"C. Exit.");
setlinestyle(0,0,3);
rectangle(170,175,400,205);
break;
}
}
if(i=100)exit(0);/*如果按键超过100次退出*/
switch(choice)/*这里引用函数,实现所要的功能*/
{
case 1: cleardevice();
setbkcolor(4);
settextstyle(3,0,4);
outtextxy(160,120,"No.1 have not built."); break;
case 2: cleardevice();
setbkcolor(4);
settextstyle(3,0,4);
outtextxy(160,150,"No.2 have not built.");
break;
case 3: exit(0);
}
getch();
closegraph();
}
对于命令行菜单,直接通过不断刷新输出来模拟菜单行为。
例程:
#include stdio.h
#include stdlib.h
#include string.h
int n,t,k;
int m;
char s1[20],s2[20],c;
char **l;
char *num[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
void menu()
{
printf("\n\n\t\t*******************************************************\n");
printf("\t\t** 1.查找字符串S1中S2出现的次数 **\n");
printf("\t\t** 2.统计字符串中大小写字母,数字出现的次数 **\n");
printf("\t\t** 3.将数字翻译成英语 **\n");
printf("\t\t** 4.结束 **\n");
printf("\t\t*******************************************************\n");
printf("\t\t 您的输入:");
fflush(stdin);
scanf("%d",n);
}
void check()
{
char a[20],b[20];
int j=0,k,m,l=0;
int t=0,n=0;
printf("请输入主字符串:\n");
scanf("%s",a);
k=strlen(a);
printf("请输入子字符串:\n");
scanf("%s",b);
m=strlen(b);
for(n=0;nk;n++)
if(a[n]==b[0])
{
j++; /*记录相同的字符数*/
do
{
if(a[++n]==b[++t])
{
j++;
if(j==m)
{
l++;/*子字符串相同数*/
j=0;/*判断后相同字符数归零*/
t=-1;/*判断中if中++t;t将会归零*/
}
}
else
{
j=0;
t=0;
break;/*如果不同跳出while循环让for使n+1继续判断*/
}
}while(a[n]!='\0');/*查找完字符数组a结束*/
}
printf("子字符串出现次数:\n%d\n",l);
}
void cout()
{
int n=0,t=0,k=0;
printf("请输入一个字符串:\n");
fflush(stdin);/*清除缓冲*/
while((c=getchar())!='\n')
{
if(c='a'c='z')
n++;
if(c='A'c='Z')
t++;
if(c='0'c='9')
k++;
}
printf("有大写字母:\n%d\n",t);
printf("有小写字母:\n%d\n",n);
printf("有数字:\n%d\n",k);
}
void number()
{
l=num;
printf("请输入一个数字:(0-10)\n");
fflush(stdin);
scanf("%d",m);
printf("%d对应的英文是:\n%s\n",m,*(l+m-1));
}
void main()
{
while(1)
{
system("cls");
menu();
switch(n)
{
case 1:system("cls");check();system("pause");break;
case 2:system("cls");cout();system("pause");break;
case 3:system("cls");number();system("pause");break;
case 4:system("cls");break;
default:system("cls");break;
}
if(n==4) break;
}
printf("感谢使用\n");
}
C语言编写菜单
#includestdio.h
#includestring.h
#includestdlib.h
//值传递
void fun1(char a)
{
a = 'b';
}
//地址传递
char fun2(char* a)
{
*a = 'a';
return *a;
}
//动态分配数组
void fun3(char* a)
{
a = (char*)malloc(sizeof(char));
}
char caidan()
{
char choose[5];
printf("\n***************************************\n");
printf(" ┌──────┐\n");
printf(" │ 菜单│\n");
printf(" __________________________________\n");
printf("│ 1,按值传递 |\n");
printf("│ 2,按地址传递 |\n");
printf("│ 3,动态数组演示|\n");
printf("│ 4,退 出 |\n");
printf("└────────────────┙\n");
printf("**************************************\n\n");
do
{
printf("请输入您的选择(1-4):");
scanf("%s",choose);
}while(strcmp(choose,"1")strcmp(choose,"2")strcmp(choose,"3")strcmp(choose,"4"));
//返回选择的菜单,注意如果输入太长 这里会异常,因为choose[5],只申请了5个字节。
return choose[0];
}
void main()
{
//执行菜单的选择
while(1)
{
switch(caidan())
{
case '1':
{
char a = 'a';
fun1(a);
//按值传递 内容不变
break;
}
case '2':
{
char b = 'b';
char a = fun2(b);
//按地址传递内容会变
break;
}
case '3':
{
char* p = NULL;
fun3(p);
//动态数组分配成功
break;
}
case '4':exit(0);
}
}
}
分享文章:c语言编写函数菜单 c语言怎么写菜单
文章位置:http://cdiso.cn/article/ddgpdpo.html