I am trying to make a tolower function from scratch (for learning purposes) and keep getting this error even if I cast the correct types:
alternate.c:13:18: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'; [-Werror]
strcat(temp, (char) i + 32);
^~~~~~~~~~~~~
/usr/include/string.h:136:72: note: passing argument to parameter '__src' here
extern char *strcat (char *__restrict __dest, __const char *__restrict __src)
^
alternate.c:15:19: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *'; [-Werror]
strcat(temp, i);
^
/usr/include/string.h:136:72: note: passing argument to parameter '__src' here
extern char *strcat (char *__restrict __dest, __const char *__restrict __src)
^
alternate.c:18:17: error: incompatible integer to pointer conversion passing 'char' to parameter of type 'const char *'; take the address with & [-Werror]
strcat(temp, uppercase[i]);
^~~~~~~~~~~~
&
/usr/include/string.h:136:72: note: passing argument to parameter '__src' here
extern char *strcat (char *__restrict __dest, __const char *__restrict __src)
^
3 errors generated.
This is the code that is causing trouble:
char * toLowerCase(char * uppercase){
char * temp = "";
for(int i =0; i<strlen(uppercase); i++){
if( (int) uppercase[i] != 32){
if( (int) uppercase[i] < 97){
strcat(temp, (char) i + 32);
}else{
strcat(temp, i);
}
}else{
strcat(temp, uppercase[i]);
}
}
return temp;
}
char!=char *. Youstrcata string, not a single character. - Kevintempvariable only has enough space to store a single character. You need more. Hint 1: at leaststrlen(uppercase)long. Hint 2: you cannot use a local variable, because you cannot return it. - Jongwaretempis a string literal, and you try to modify it bystrcat- Yu Hao