Count the number of occurrences of each letter in string

前端 未结 15 2012
别跟我提以往
别跟我提以往 2020-12-10 20:02

How can I count the number of occurrences in c of each letter (ignoring case) in the string? So that it would print out letter: # number of occurences, I have c

15条回答
  •  鱼传尺愫
    2020-12-10 20:25

    #include 
    #include 
    void main()
    {
        printf("PLEASE ENTER A STRING\n");
        printf("GIVE ONLY ONE SPACE BETWEEN WORDS\n");
        printf("PRESS ENETR WHEN FINISHED\n");
    
        char str[100];
        int arr[26]={0};
        char ch;
        int i;
    
        gets(str);
        int n=strlen(str);
    
        for(i=0;i=97 && ch<=122)   
            {
                arr[ch-97]++;
            }
        }
        for(i=97;i<=122;i++)
            printf("%c OCCURS %d NUMBER OF TIMES\n",i,arr[i-97]);   
        return 0;
    }
    

提交回复
热议问题