I am trying to remove leading/trailing whitespace characters with help below helper function. When compiling i am getting warning: array subscript has type ‘char’ [-Wchar-subsc
The warning may be because you're passing a char
to the isspace()
macro. The implementation of isspace()
may be via array indexing. (The argument to the isspace()
macro is defined to be an integer the value of which can fit in an unsigned
char
).
I've just looked at ctype.h
in GNU libc, and while there's a complicated mess of macros and functions, somewhere in the definition of isspace()
there's an array being indexed.
See if isspace((unsigned char) *str)
gets rid of the warning.