-Wchar-subscripts : 配列の添字が char 型の場合に警告する
上記の警告を生成するコード例。
#include<stdio.h>
int main()
{
int a[10]; //or even char a[10];
char c=5;
printf("%d",a[c]); //you might used like this in your code array with character subscript
return 0;
}
あなたのコード(投稿されていません)では、上記のようにchar添え字を使用できます。
コードで -Wchar-subscripts 警告を生成する main の例:
int main()
{
char c=20;
char s[c];
printf("Enter string:");
fgets(s,sizeof(s),stdin);
printf("String before removal of spaces : \n%s",s);
printf("%c",s[c]); //accessing s[c],array element with char subscript or else any Expression you might used this
printf("test text\n");
strcpy(s,removeSpace(s));
printf("String after removal of spaces : \n%s",s);
printf("test text\n");
return 0;
}
しかし、投稿したコードには No char subscript があります。main を追加してコードをテストしました。警告やエラーを再現しませんでした 。 gcc -Wall -Werror file.cでコンパイルしました。
それでもわからない場合は、コード全体を投稿してください。
警告とエラーを生成しなかったコードをテストします。
#include<stdio.h>
#include<string.h>
#include <ctype.h> //included this to use isspace
char *removeSpace(char *);
char *removeSpace(char *str )
{
char *end;
// Trim leading space
while(isspace(*str))
str++;
if(*str == 0) // All spaces?
return str;
// Trim trailing space
end = str + strlen(str) - 1;
while(end > str && isspace(*end)) end--;
// Write new null terminator
*(end+1) = 0;
return str;
}
int main()
{
char s[20];
printf("Enter string:");
fgets(s,sizeof(s),stdin);
printf("String before removal of spaces : \n%s",s);
printf("test text\n");
strcpy(s,removeSpace(s));
printf("String after removal of spaces : \n%s",s);
printf("test text\n");
return 0;
}