|
发表于 2021-8-2 22:54:42
|
显示全部楼层
本楼为最佳答案
变量没有初始化
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char str1[128];
- //char str2[128];
- //char str3[2];
- char str2[128] = {0};
- char str3[2] = {0};
- char base = ' ';
- char turn;
- int a, b, c;
- int d = 0;
- int max, num = 0;
- int i, j;
- int abs[95] = {0};
- printf("请输入英文文本:");
- scanf("%[^\n]", str1);
- a = strlen(str1);
- while( base < 126)
- {
- for(i=0; i<a; i++)
- {
- b = str1[i] - base;
- c = (int)base;
- if(b == 0)
- {
- abs[c-32] += 1;
- }
- }
- base += 1;
- }
- for(j=0; j<95; j++)
- {
- if(abs[j] != 0)
- {
- turn = j + 32;
- str3[0] = turn;
- strcat(str2, str3);
- d += 1;
- }
- if(abs[j] > num)
- {
- max = j;
- num = abs[j];
- }
- }
- printf("你总共输入了%d个字符,其中不同的字符个数有%d个。\n", a, d);
- printf("它们是:%s\n", str2);
- printf("出现次数最多的是字符是‘%c’,它总共出现了%d次。\n", max+32, num);
- return 0;
- }
复制代码 |
|