[英]incompatible integer to pointer conversion assigning to 'char *' from 'int' when converting char* to char* lowercase
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.我正在尝试使用
char *
并将其转换为小写,然后再通过测试运行它。 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.对我做错了什么的解释也会很棒。
You are creating a two-dimensional array using char *s[testWordLen];
您正在使用
char *s[testWordLen];
创建一个二维数组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]);
当你像这样取消引用它时:
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];
解决方法是:将变量声明为
char s[testWordLen];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.