C : 警告:赋值使指针从整数而不进行强制转换 [默认启用] [英] C : warning: assignment makes pointer from integer without a cast [enabled by default]
本文介绍了C : 警告:赋值使指针从整数而不进行强制转换 [默认启用]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
#include<stdio.h>
#include<stdlib.h>
void main() {
FILE *fp;
char * word;
char line[255];
fp=fopen("input.txt","r");
while(fgets(line,255,fp)){
word=strtok(line," ");
while(word){
printf("%s",word);
word=strtok(NULL," ");
}
}
}
这是我收到的警告.
token.c:10:7: warning: assignment makes pointer from integer without a cast [enabled by default]
word=strtok(line," ");
^
token.c:13:8: warning: assignment makes pointer from integer without a cast [enabled by default]
word=strtok(NULL," ");
^
word
被声明为 char*
.那为什么会出现这个警告?
The word
is declared as char*
. Then why this warning arises?
推荐答案
Include #include
以获得 strtok()
的原型.
Include #include <string.h>
to get the prototype for strtok()
.
您的编译器(如在 C99 之前的 C 中)假定 strtok()
会因此返回 int
.但不提供函数声明/原型在现代 C(自 C99)中无效.
Your compiler (like in pre-C99 C) assumed strtok()
returns an int
because of that. But not providing function declaration/prototype is not valid in modern C (since C99).
在 C 中使用了一个旧规则,允许隐式函数声明.但是 implicit int rule 从 C99 开始就从 C 语言中删除了.
There used an old rule in C which allowed implicit function declarations. But implicit int rule has been removed from C language since C99.
这篇关于C : 警告:赋值使指针从整数而不进行强制转换 [默认启用]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文