baybaye 2015-11-21 15:07 采纳率: 70%
浏览 1604
已采纳

c语言问题

Write a program using the given functions 用给定函数编写程序
Must use a structure type 必须使用结构类型

图片说明

图片说明

图片说明

图片说明

  • 写回答

5条回答 默认 最新

  • MR_Radish666 2015-11-25 06:17
    关注
    
    
    #include<stdio.h>
    #include<stdlib.h>
    #include<CONIO.H>
    typedef struct String{
        char string[100];
    }SqList;
    int count = 0; //统计数据长度
    void Print(SqList *L)
    {
        for(int i=0;L->string[i]!='\0';i++){
            printf("%2c",L->string[i]);
        }
        printf("\n");
    }
    void Creat_List ( SqList *L )
    {
            printf("Input a string:");
            scanf( "%s",&L->string);
    }//录入数据完成
    // 
    void Count(SqList *L)
    {
        count = 0;
        for(int i=0;L->string[i]!='\0';i++){
            count++;
        }
    }
    
    void LoopUp(SqList* L)
    {   
        printf("Find a character :");
        char ch;
        int m=0;
        int i=0;
        Count(L);
        getchar();
        scanf( "%c",&ch);
        for(i = 0;i<count;)
        {
    
            if(ch == L->string[i]) //如果找到
            {
                i++;
                printf("%3c is in the list\n",ch);
                break;
            } else
            {
                i++;
                m++;   //m用来表示break的时候是否<=i
            }
        }
        if(m==i)
        {
            printf("%3c is not in the list\n",ch);
        }
    }
    
    
    int main ()
    {
        int k;
         SqList L;
        while( 1 ){
            printf( "-------------------MENU-------------------\n" );
            printf( "1.String to list \n" );
            printf( "2.Show the list \n" );
            printf( "3.LoopUp  \n" );
            printf( "4.Count   \n" );
            printf( "5.Exit   \n" );
            printf("Choose the item(1~5):");
            scanf( "%d",&k );
            switch( k )
            {
                case 1:
                     {
                        Creat_List(&L);
                     }break;
                case 2:
                    {
                        printf("List:");
                        Print(&L);
                    }break;
                case 3:
                    {
                        LoopUp(&L);
                    }break;
                case 4:
                    {
                        Count(&L);
                        printf("String length : %d\n",count);
                    }break;
                case 5:
                    exit(1);break;
                default:printf("Error");
            } 
        }
        return 0;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    运行结果:
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):1
    Input a string:abcdefg
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):2
    List: a b c d e f g
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):3
    Find a character :a
    a is in the list
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):3
    Find a character :z
    z is not in the list
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):4
    String length : 7
    -------------------MENU-------------------
    1.String to list
    2.Show the list
    3.LoopUp
    4.Count
    5.Exit
    Choose the item(1~5):5
    Press any key to continue

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试