I wrote a function that determines if a word is an isogram or not. I am close to the end but I have got few errors which I am not able to understand, because one of my compiler understands it but another doesn't.
The errors are:
solution.c:23:9: warning: array subscript is of type 'char' [-Wchar-subscripts]
isogram[c]=isogram[c]+1;
^~
solution.c:23:20: warning: array subscript is of type 'char' [-Wchar-subscripts]
isogram[c]=isogram[c]+1;
^~
2 warnings generated.
And the code:
bool IsIsogram(char *str)
{
int isogram[256];
int i,len_str,cpt,occs;
char c;
for (i = 0; str[i] != '\0'; i++) {
len_str=i;
}
for (i=0; i<=256;i++){isogram[i]=0;}
for(i=0; i <= len_str; i++){
c = str[i];
c = tolower(c);
str[i] = c;
}
cpt=0;
for (i = 0; i < len_str; i++) {
c = str[i];
isogram[c]=isogram[c]+1;
}
for (i = 0; i < 256; i++) {
occs = isogram[i];
if (occs > 0) {
cpt++;
}
}
if (cpt==len_str) {
return true;
}
else{
return false;
}
}