Home > Software design >  incompatible integer to pointer conversion assigning to 'char *' from 'int' when
incompatible integer to pointer conversion assigning to 'char *' from 'int' when

Time:11-04

I have this annoying warning when I go to compile my code. I'm trying to take a char * and convert it to lower case before I run it through a test. My code compiles just fine but I want to learn how to get rid of this warning. Other posts with this same error don't provide me with what I need to change to remove this error.

//convert to lower case
char *c = "WORD TO LOWER";
char *s[testWordLen];
for (int i = 0; i < testWordLen; i  )
{
    s[i] =  tolower((unsigned char) c[i]);
}

An explanation of what I'm doing wrong would be great too.

CodePudding user response:

You are creating a two-dimensional array using char *s[testWordLen];; that is, a pointer to an array of chars. When you dereference it like this: s[i] = tolower((unsigned char) c[i]);, you assign a single character to an array.

The fix is this: declare the variable as char s[testWordLen];

  • Related