【发布时间】:2021-08-20 02:36:07
【问题描述】:
作为萨拉姆·阿莱科姆。 在这段代码中,我试图打印特定段落的每个字母字符的重复次数,如下所示:
a ----> "Number of recurrences"
b ----> "Number of recurrences"
and so on...
通过使用 stricmp 函数在每个循环中比较两个数组的元素。但它根本不打印任何东西和0个错误,这是什么问题?!?!?!?!?
#inlcude <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include <string.h>
#include <time.h>
void main()
{
int i, j;
int z = 0;
char h, g;
char y[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char x[620] = {"C is a general purpose computer programming language developed in 1972 by Dennis Ritchie at the Bell Telephone laboratories for use with the unix operating system... and more which is not visible in the image."};
for(j = 0; j < 26; j++)
{
for(i = 0; i < 609; i++)
{
if(stricmp(y[j], x[i]) == 0)
{
z++;
}
}
printf("y[j] -------> %d", z);
}
}
【问题讨论】:
-
请勿发布代码图片。将代码本身以文本形式复制并粘贴到问题中。
-
stricmp需要字符串,而不是chars。启用您的编译器警告。 -
在每个内部for循环启动后z的值为零。