導航:首頁 > 編程語言 > c多級菜單代碼

c多級菜單代碼

發布時間:2023-08-28 08:42:51

『壹』 怎樣用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多級菜單代碼相關的資料

熱點內容
linux裝apache 瀏覽:272
手機谷歌打不開網站怎麼辦 瀏覽:110
燈控台編程好了怎麼使用 瀏覽:342
如何用金山毒霸切斷網路連接 瀏覽:873
怎麼設置文件打開密碼怎麼設置 瀏覽:5
網路小說用什麼寫 瀏覽:956
擴展名為rm的文件如何打開 瀏覽:707
導入android項目沒有rjava 瀏覽:899
帶英文和數字的文件名 瀏覽:843
黃山數控編程培訓在哪裡 瀏覽:111
win10俠盜5無限讀取 瀏覽:557
js工廠模式 瀏覽:927
iphone6s清理緩存 瀏覽:465
ug編程怎麼選不上字體 瀏覽:435
pc文件加密哪個好 瀏覽:393
蘋果軟體更新4位密碼 瀏覽:96
手機如何將文件弄成文件夾 瀏覽:275
swordigo第四關 瀏覽:996
t420win10網卡驅動 瀏覽:805
ps怎麼打開dxf文件怎麼打開 瀏覽:698

友情鏈接