【发布时间】:2016-02-09 13:47:02
【问题描述】:
我正在学习如何使用 malloc 创建动态数组。我正在尝试为其分配字符,然后打印它们。该程序在我运行时可以运行,但是我不断收到以下警告:
位置 (1):警告:不兼容的整数到指针转换从 'int' [-Wint-conversion] 分配给 'char *'
Location(2):警告:格式指定类型“int”但参数的类型为“char *”[-Wformat]
如何解决此问题,为什么我不断收到此警告?
int main(void) {
char **board = (char **) malloc(26*26*sizeof(char));
for(int i = 0; i < 25; i++) {
*(board + i) = i + 'a'; //location (1)
printf("%c\n", *(board + i)); //location (2)
}
free(board);
return (EXIT_SUCCESS);
}
【问题讨论】:
-
没有二维数组。指针不是数组。