I'm following along that tutorial, I'm running WindowsXP 32-bit with cygwin compiler, The tutorial asks me to run this code:
#include <stdio.h>
#include <ctype.h>
// forward declarations
int can_print_it(char ch);
void print_letters(char arg[]);
void print_arguments(int argc, char *argv[])
{
int i = 0;
for(i = 0; i < argc; i++) {
print_letters(argv[i]);
}
}
void print_letters(char arg[])
{
int i = 0;
for(i = 0; arg[i] != '\0'; i++) {
char ch = arg[i];
if(can_print_it(ch)) {
printf("'%c' == %d ", ch, ch);
}
}
printf("\n");
}
int can_print_it(char ch)
{
return isalpha(ch) || isblank(ch);
}
int main(int argc, char *argv[])
{
print_arguments(argc, argv);
return 0;
}
But I keep running into this warning:
$ make ex14
cc -Wall -g ex14.c -o ex14
ex14.c: In function ?can_print_it?:
ex14.c:34:5: warning: array subscript has type ?char? [-Wchar-subscripts]
return isalpha(ch) || isblank(ch);
^
ex14.c:34:5: warning: array subscript has type ?char? [-Wchar-subscripts]
I have tried searching around, while I have found a lot of threads talking about a similar error, none of their answers/solutions worked on my code, and I couldn't find a question related to Learn C The Hard Way exercise 14.
So what should I do to get rid of that warning?
(unsigned char)ch. The standard mandates the passed value to both of those (isalphaandisblank) must be representable asunsigned charor the behavior is undefined.can_print_it(char ch);tocan_print_it(int ch);to fix it.can_print_itis to exclude all but alphabetic chars or spaces. Punctuation, digits, etc, are all excluded, where they would not be withisprint.