-Wchar-subscripts : Warn if an array subscript has type char
Example code which produces above warning.
#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;
}
In your code(Which is not posted), You might used char subscript As Like above.
Example of main which produces the -Wchar-subscripts warning in your code:
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;
}
But there is No char subscript , in the code which you have posted. tested your code by adding main. did not reproduce any warning or error.I did compilation with gcc -Wall -Werror file.c .
if you still did not figure , post your whole code.
test Code Which did not produce any warnings and errors:
#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;
}