當前位置:首頁 » 編程語言 » c語言系統菜單
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言系統菜單

發布時間: 2022-06-25 18:34:03

A. 如何用c語言編寫菜單項

在C語言中,通常菜單有系統菜單、彈出菜單、下拉菜單等,不知道你要做哪一種。
菜單的製作,通常需要一下幾個步驟:
1、定義菜單項目數據結構;
2、定義你要做的彈出菜單或下拉菜單或...的數據結構;
3、建立菜單內容;
4、載入菜單內容;
5、在某個位置上顯示(包含保存原有內容以備關閉菜單後恢復覆蓋的屏幕,測試菜單顯示區域根據實際情況調整顯示區域);
6、游標移動,菜單項目顏色變化;
7、執行選中菜單項程序;
8、關閉菜單。
如果純粹用C語言寫,寫一個通用的,估計至少要上千行程序代碼,以前做過,後來不再使用C語言了,放在機器上,就找不到了。要不就放上去了。

B. 怎樣用C語言編寫菜單

  1. 對於窗口組件菜單,需要根據不同平台,通過圖形編程介面,進行菜單的編制。

    常式:

    #include<stdio.h>
    #include<graphics.h>
    #include<conio.h>
    voidmain()
    {
    charstr;
    inti,k,choice=1;
    intgd=DETECT,gm;
    initgraph(&gd,&gm,"");
    setbkcolor(2);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    outtextxy(140,150,"B.TheDigitalClock.");
    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)
    {case1:setlinestyle(0,0,3);
    rectangle(170,115,400,145);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    settextstyle(3,0,3);
    outtextxy(140,150,"B.TheDigitalClock.");
    outtextxy(140,180,"C.Exit.");
    break;
    case2:setlinestyle(0,0,3);
    rectangle(170,145,400,175);
    settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    settextstyle(3,0,3);
    outtextxy(140,150,"B.TheDigitalClock.");
    settextstyle(3,0,3);
    outtextxy(140,180,"C.Exit.");
    break;
    case3:settextstyle(3,0,3);
    outtextxy(140,120,"A.TheMockClock.");
    outtextxy(140,150,"B.TheDigitalClock.");
    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)/*這里引用函數,實現所要的功能*/
    {
    case1:cleardevice();
    setbkcolor(4);
    settextstyle(3,0,4);
    outtextxy(160,120,"No.1havenotbuilt.");break;
    case2:cleardevice();
    setbkcolor(4);
    settextstyle(3,0,4);
    outtextxy(160,150,"No.2havenotbuilt.");
    break;
    case3:exit(0);
    }
    getch();
    closegraph();
    }
  2. 對於命令行菜單,直接通過不斷刷新輸出來模擬菜單行為。

    常式:

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    intn,t,k;
    intm;
    chars1[20],s2[20],c;
    char**l;
    char*num[]={"one","two","three","four","five","six","seven","eight","nine","ten"};
    voidmenu()
    {
    printf(" ******************************************************* ");
    printf(" **1.查找字元串S1中S2出現的次數** ");
    printf(" **2.統計字元串中大小寫字母,數字出現的次數** ");
    printf(" **3.將數字翻譯成英語** ");
    printf(" **4.結束** ");
    printf(" ******************************************************* ");
    printf(" 您的輸入:");
    fflush(stdin);
    scanf("%d",&n);
    }
    voidcheck()
    {

    chara[20],b[20];
    intj=0,k,m,l=0;
    intt=0,n=0;
    printf("請輸入主字元串: ");
    scanf("%s",a);
    k=strlen(a);
    printf("請輸入子字元串: ");
    scanf("%s",b);
    m=strlen(b);
    for(n=0;n<k;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]!='');/*查找完字元數組a結束*/
    }
    printf("子字元串出現次數: %d ",l);
    }
    voidcout()
    {
    intn=0,t=0,k=0;
    printf("請輸入一個字元串: ");
    fflush(stdin);/*清除緩沖*/
    while((c=getchar())!=' ')
    {
    if(c>='a'&&c<='z')
    n++;
    if(c>='A'&&c<='Z')
    t++;
    if(c>='0'&&c<='9')
    k++;
    }
    printf("有大寫字母: %d ",t);
    printf("有小寫字母: %d ",n);
    printf("有數字: %d ",k);
    }
    voidnumber()
    {
    l=num;
    printf("請輸入一個數字:(0-10) ");
    fflush(stdin);
    scanf("%d",&m);
    printf("%d對應的英文是: %s ",m,*(l+m-1));
    }
    voidmain()
    {
    while(1)
    {
    system("cls");
    menu();
    switch(n)
    {
    case1:system("cls");check();system("pause");break;
    case2:system("cls");cout();system("pause");break;
    case3:system("cls");number();system("pause");break;
    case4:system("cls");break;
    default:system("cls");break;
    }
    if(n==4)break;
    }
    printf("感謝使用 ");
    }

C. C語言菜單怎麼弄

中國電力出版社書號為5123-5504-0的C語言程序設計書上有介紹方法:
現在,通過一個簡單的開發實例來理解上述概念。該應用軟體運行時,首先出現一個菜單,用戶選擇某一菜單項後進入相應子模塊處理具體問題,處理結束後回到主菜單。當在主菜單上選擇退出功能後,軟體運行結束。將各子模塊劃分成子函數後,進一步將菜單初始化和界面顯示、選擇功能劃分成子函數,最終設計出來的函數代碼框架如下:
#include <stdio.h>
//菜單初始化函數:設置菜單文字
void InitMenu( char *Menu[] )
{
Menu[0]="1. 菜單項1名稱 ";

}
// 顯示菜單、接受用戶選擇函數
// 初學者可以使用printf、getch函數實現基本交互
// 進階後可以引入圖形、字體、功能鍵、滑鼠等元素進行人機交互
int ChooseMenu( char *Menu[], int MaxItem )
{
return 1; // 選擇菜單1

return 0; // 選擇退出
}
//模塊一
void sub1(void)
{

}
void main( void )
{
char *Menu[10],MaxItem=10; //指針數組存儲菜單名稱:0-9項
intdone=0; //退出標志,為1時退出
InitMenu( Menu ); //調用菜單初始化模塊
do
{
// 每輪循環都重新顯示界面、接受用戶選擇、根據用戶選擇執行相應分支
switch( ChooseMenu(Menu, MaxItem ) )
{
case 1:
sub1();
break;
case 2:

case 0:
done=1;
}
}while(!done);
}
在結構那一章還有一個課程設計的菜單,太長了,感興趣找書看看吧

D. c語言 這個怎樣菜單化

用C語言非常難以實現菜單化。
如果想做出菜單樣式的,可以採用C#比較好。C的應用對象一般是面向硬體、底層,跟匯編有的一拼,而對這種應用程序,並不是它的強項。

E. 關於c語言菜單命令

使用死循環來輸出菜單。設置一個退出死循環的選項。
使用switch()來執行對應程序。
while(1)
{
menu(){
printf("\t\t 歡迎使用學生成績管理系統\n");
printf("\t\t\t1:錄入學生信息\n");
printf("\t\t\t2:排序列印成績\n");
printf("\t\t\t3:統計分布情況\n");
printf("\t\t\t4:查詢學生信息\n");
printf("\t\t\t5:退出\n");
printf("^_^ 提示:請輸入操作命令 > > > >:");
scanf("%d",&p);
}
switch(p)
{
case 1:{程序1};break;//程序你可以模塊化,編成對應的函數,這樣看起來更美觀
case 2:{程序2};break;
......
case 5:return;break;
}
}

F. 怎麼用C語言編寫菜單

#include "stdio.h"
#include "stdlib.h"
#include "dos.h"
#include "windows.h"
char choice1;
void main()
{
void menue1();
printf("歡迎進入Ben的作業查詢系統!");
menue1();
}
void menue1()
{
void choicemenue1();
printf("\n請按照以下列表選擇您想要查看的章節:");
printf("\n編號\t章節\n 1\t第一章\n 2\t第二章\n");
printf("請輸入編號進行選擇:");
choicemenue1();
}
void choicemenue1()
{
choice1=getch();
switch(choice1)
{
void menuechapter1();
void menuechapter2();
void menue1();
case '1':menuechapter1();break;
case '2':menuechapter2();break;
default:printf("\n輸入錯誤!請重新選擇!\n"),menue1();
}}
void menuechapter1()
{
char choiceex;
printf("\n您選擇的是第%c章",choice1);
printf("\n現在請選擇本章節的題目。");
printf("\n請按照以下列表選擇題目:");
printf("\n編號\t題目編號\n1\t第1題\n2\t第2題\n");
printf("請選擇:");
switch(choiceex=getch())
{
void c1_1();
void c1_2();
case '1':c1_1();break;
case '2':c1_2();break;
default:
printf("\n你個白痴!這也能選錯!不讓你重選了!");
printf("\n按任意鍵以退出!");
getch();
exit(0);
}
}
void menuechapter2()
{
char choiceex;
printf("\n您選擇的是第%c章",choice1);
printf("\n現在請選擇本章節的題目。");
printf("\n請按照以下列表選擇題目:");
printf("\n編號\t題目編號\n1\t第1題\n2\t第2題\n");
printf("\n請選擇:");
switch(choiceex=getch())
{
void c2_1();
void c2_2();
case '1':c2_1();break;
case '2':c2_2();break;
default:
printf("\n你個白痴!這也能選錯!不讓你重選了!");
printf("\n按任意鍵以退出!");
getch();
exit(0);
}
}
void c1_1()
{
char howtorun;
printf("現在請選擇考察方式:");
printf("\n編號\t考察方式\n 1\t運行程序\n 2\t查看源代碼\n 3\t返回主菜單\n 4\t退出程序\n");
printf("請選擇:");
switch(howtorun=getch())
{
void runc1_1();
void menue1();
case '1':runc1_1();break;
case '2':printf("\n"),system("type \\caidan\\chapter1\\c1_1.c"),printf("\n"),getch();break;
case '3':menue1();break;
case '4':exit(0);break;
default:
printf("程序即將結束!哈哈哈……");
printf("按任意鍵以結束程序!");
getch();
exit(0);
}}
void c1_2()
{
printf("c1_2 is OK!");
}void c2_1()
{
printf("c2_1 is OK!");
}void c2_2()
{
printf("c2_2 is OK!");
}
void runc1_1()
{
int a,b,max;
printf("\nPlease input two integer numbers:");
printf("a=?,b=?\n");
scanf("%d,%d",&a,&b);
max=a>b?a:b;
printf("The max number is %d",max);
}
大概就是這樣做的。。

G. 怎麼寫簡單的C語言菜單

1、使用輸出函數即可。

2、常式:

#include<iostream>
#include<stdlib.h>
#include<conio.h>
#include<ctype.h>
usingnamespacestd;
voidxuanzepaixu()//選擇排序函數
{
printf("待添加,請按任意鍵繼續...");
getchar();
}
voiderfenpaixu()//二分查找函數
{
printf("待添加,請按任意鍵繼續...");
getchar();
}
voidmenu()//主菜單
{
system("cls");//清屏
printf(" 菜單 ");
printf(" #***********************# ");
printf(" #1選擇排序# ");
printf(" #2二分查找# ");
printf(" #3返回# ");
printf(" #4---關閉# ");
printf(" #***********************# ");
printf(" 請選擇(1-4)=:");
}
voidmain()
{
charselect;
while(1)
{
menu();
system("COLOR9f");
scanf("%c",&select);
if(select=='3')
break;//返回上級菜單
else
{
getchar();//讀入回車符
if(!isdigit(select))//如果不是數字字元
{
printf(" 7Yourselectmaybewrong,mustenterthedigit! ");_getch();
}
else
{

switch(select)
{
case'1':xuanzepaixu();break;
case'2':erfenpaixu();break;
case'4':exit(0);//直接退出
default:
{
printf(" 77Yourselecteddigitmaybewrong,selectagain! ");
_getch();
break;
}
}
}
}
};
}

H. C語言菜單設計

const是常量的關鍵字,unsigned無符號,char是字元型,後面是變數
意思就是定義常量
無符號字元串型變數
menu...
=
***
每個menux_x[]
都包含一個字元串,就是後面的那個{}里的內容

I. c語言 如何調用系統開始菜單的「運行」命令

你要彈出
系統開始菜單的「運行」的
對話窗,對嗎?
下面就是。
#include
#include
#include
#include
void
main()
{
keybd_event(VK_LWIN,0,0,0);
keybd_event(0x52,0,0,0);
keybd_event(VK_LWIN,0,KEYEVENTF_KEYUP,0);
}
編譯時必須鏈接
user32.lib
cl
prog.c
user32.lib
等於
Start->Run

J. c語言菜單模板

#include
#include
void function1(){
}
void function2(){
}
void function3(){
}
int main(int argc, char *argv[]){//主函數
char choice; //暫存選擇
while(true){
printf("-----------------主題-----------21/11/14 18:38\n\n");
printf("1:功能1\n2:功能2\n3:功能3\n4:退出\n請選擇操作:");
scanf("%c",&choice);
switch(choice){
case '1' : function1();break;
case '2' : function2();break;
case '3' : function3();break;
case '4' : return 0;break;
}
system("cls");
}
}