当我运行此程序时,我收到警告“数组下标具有类型'char'”。 请帮我,它出错了。我使用的代码::块IDE警告:数组下标具有类型char
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
void NoFive()
{
long long int cal;
char alpha[25];
char given[100] = "the quick brown fox jumped over the cow";
int num[25];
int i, k;
char j;
j = 'a';
k = 26;
cal = 1;
for(i = 0; i <= 25; i++)
{
alpha[i] = j++;
num[i] = k--;
// printf("%c = %d \n", alpha[i], num[i]);
}
for(i = 0; i <= (strlen(given) - 1); i++)
{
for(j = 0; j <= 25; j++)
{
if(given[i] == alpha[j]) ***//Warning array subscript has type char***
{
cal = cal * num [j]; ***//Warning array subscript has type char***
}
else
{
}
}
}
printf(" The value of cal is %I64u ", cal);
}
main()
{
NoFive();
}
http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html将阐明为什么这是一个警告。 – 2012-04-02 07:27:08
对于(i = 0; i <= 25; i ++)'也是错误的(两次)。应该是'for(i = 0; i <25; i ++){...}'数组有25个元素。而'for(i = 0; i <=(strlen(given) - 1); i ++)'是有争议的。 – wildplasser 2012-04-26 18:15:23