warning: assignment makes pointer from integer without a cast错误

if((in=fopen("read.in","r"))==NULL)

 

没注意运算符的优先级,导致了warning: assignment makes pointer from integer without a cast错误,好久才找出来

原语句是这样的:

if(in=fopen("read.in","r")==NULL)

分析:由于==的优先级高于=,所以会先计算fopen("read.in","r")==NULL这个表达式,这个表达式的计算结果会是TRUE or FAILUER,也就是int型,而in是char*,所以将int型赋值给char*,就会报warning: assignment makes pointer from integer without a cast这样的错误。

修改:

if if((in=fopen("read.in","r"))==NULL)

这样就ok了。

你可能感兴趣的:(null,Integer)