为什么错误
#include <stdio.h>
int main(void)
{
int *p, size, i;
FILE *fp;
fp = fopen("input.txt","r");
fscanf(fp, "%d", &size);
p = (int*)malloc(size*sizeof(int)); //error
for (i = 0; i <size; i++)
fscanf(fp, "%d", &p[i]);
for (i = size-1; i>= 0; i--)
printf("%d\n", p[i]);
free(p);
fclose(fp);
return 0;
}
我在 ubuntu 上使用“Geany”
在 Geany 编译器上:
fileName.c:11:2:警告函数“malloc”的隐式声明 [-Wimplicit-function-declaration] fileName.c:11:12:警告:内置函数“malloc”的隐式声明不兼容 [默认启用] fileName.c:18:12:警告:函数'free'的隐式声明 [-Wimplicit-function-declaration] fileName.c:18:12:警告:内置函数'free'的隐式声明不兼容 [启用-by default] 编译成功完成