Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String sprintf(将int转换为char[])_String_Int_Type Conversion_Printf - Fatal编程技术网

String sprintf(将int转换为char[])

String sprintf(将int转换为char[]),string,int,type-conversion,printf,String,Int,Type Conversion,Printf,在我的程序中,我尝试将int转换为char[20] 我尝试通过以下方式来实现这一点: char str[20]; sprintf(str, "%d", timer); 其中计时器是int 但是当我构建这段代码时,我得到了以下警告 Type implicit declaration of function 'sprintf' [-Wimplicit-function-declaration] incompatible implicit declaration of buil

在我的程序中,我尝试将int转换为char[20]

我尝试通过以下方式来实现这一点:

  char str[20];    
  sprintf(str, "%d", timer);
其中计时器是int

但是当我构建这段代码时,我得到了以下警告

Type implicit declaration of function 'sprintf' [-Wimplicit-function-declaration]   
incompatible implicit declaration of built-in function 'sprintf' [enabled by default]   
这是什么意思

注:(我已经包括string.h和stdlib.h)


太好了,我在代码中添加了stdio.h,现在警告消失了,结果给了我一个更大的错误


未定义的对“\u sbrk”的引用

您可能需要将
sprintf(str,“%d”,timer)
放在函数内部(而不是源代码的全局部分)

stdio.h
比如:

#include <stdlib.h>
char str[20];
// SPOT #1
int f() {
    sprintf(str, "%d", timer); // this won't work if placed on SPOT #1
}
#包括
char-str[20];
//点#1
int f(){
sprintf(str,“%d”,timer);//如果放在现场,这将不起作用#1
}

要使用
sprintf()
您必须
#包括
,您要确保还添加了对它的引用,它位于函数内部。。。所以这绝对不是事实是的,他是,我是最伟大的。我甚至不能接受他的飞机,他太快了
stdio.h