【发布时间】:2019-12-04 03:06:28
【问题描述】:
我从来没有理解过这个错误,而且我一直遇到类似的错误,这真的很令人沮丧,因为我找不到解决方案。 (如果有其他的请不要因为我找不到它而抨击我)。
看一段简单的代码:
#include <stdio.h>
#include <stdlib.h>
int main(int argc,char *argv[]){
char s[10];
int x = strtol(argv[1], &s, 10);
printf("%d", x);
printf("%s", s);
return 0;
}
我不断收到这些错误,但我真的不明白为什么:
警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“strtol”的参数 2 int x = strtol(argv[1], &s, 10);
和
注意:预期为“char ** restrict”,但参数类型为“char (*)[10]”
当我将 char s[10] 更改为 char *s 时,我在使用 strtol 的行上收到一个段错误。我不明白出了什么问题,有人可以解释一下吗?提前致谢。
【问题讨论】:
标签: c