Hi, I'm having a problem using GCC 3.4.2, I'm getting 2 warnings at these lines:

int check_format(char array[]){

int i= 0;

-------->while(array[i]!='\0'&&array[i]!='\n'){

--------->if( (!isdigit(array[i])) && (array[i]!=' ') && (array[i]!='-') && (count==9 && array[i]!='X') )

program.c:50: warning: subscript has type `char'
program.c:53: warning: subscript has type `char'

On GCC 4.1.2 it compiles fine, but I need it to work on both. Do you have any idea on how to fix this?

Thanks in advance.

The only part of the code you posted that the warning makes sense on is:

!isdigit(array[i])

And a cast can fix that, because isdigit expects an unsigned char value or EOF:

!isdigit ( (unsigned char)array[i] );

Post a more complete example that exhibits the problem, please.

Yes, it as that line, altough I casted it to int and it worked well. I don't understand why it showed 3 warnings instead of one. Thanks for the answer.

>I don't understand why it showed 3 warnings instead of one.
That's a mystery of the parser. It's extremely difficult for a compiler to avoid inaccurate and/or cascading error messages when it comes to syntax problems. Often you'll get one real error and half a dozen or more false positives that stem from the real error. That's why it's recommended to look for problems in the range of about five lines above and below the line that your error message reports. It's also one reason why debugging is so much harder than writing code. ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.