C的误差:未定义参考“_itoa” [英] C Error: undefined reference to '_itoa'

查看:880
本文介绍了C的误差:未定义参考“_itoa”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个整数转换为字符写入一个文件,使用该行:

I'm trying to convert an integer to a character to write to a file, using this line:

fputc(itoa(size, tempBuffer, 10), saveFile);

和我收到此警语和信息:

and I receive this warning and message:

警告:的隐式声明itoa

未定义参考_itoa

我已经包含stdlib.h中,并正在与编译:

I've already included stdlib.h, and am compiling with:

gcc -Wall -pedantic -ansi

任何帮助将是AP preciated,谢谢。

Any help would be appreciated, thank you.

推荐答案

itoa 不是标准的一部分。我怀疑不是 -ansi 是preventing您使用它,或者它根本不可用。

itoa is not part of the standard. I suspect either -ansi is preventing you from using it, or it's not available at all.

我会建议使用的sprintf()

如果您使用C99标准走,你可以使用的snprintf()这当然是更安全的。

If you go with the c99 standard, you can use snprintf() which is of course safer.

char buffer[12];
int i = 20;
snprintf(buffer, 12,"%d",i);

这篇关于C的误差:未定义参考“_itoa”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆