ANSI C,整串没有可变参数的函数 [英] ANSI C, integer to string without variadic functions
本文介绍了ANSI C,整串没有可变参数的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在与支持ANSI C PLC的工作,但使用自己的GNU编译器,它不编译任何参数可变型函数之类的东西itoa的味道。因此,使用的sprintf&安培;合。不是整数转换为字符串的一个选项。任何人都可以引导我到一个网站,一个强大的,sprintf-免费实现itoa是上市或在这里发表一个合适的算法?先谢谢了。
I'm currently working with a PLC that supports ANSI C, but uses its own flavour of the GNU compiler, which doesn't compile any variadic functions and things like itoa. So using sprintf & co. isn't an option for converting integers to strings. Can anyone guide me to a site where a robust, sprintf- free implementation of itoa is listed or post a suitable algorithm here? Thanks in advance.
推荐答案
这是从K&安培; R:
This is from K&R:
void itoa(int n, char s[])
{
int i, sign;
if ((sign = n) < 0) /* record sign */
n = -n; /* make n positive */
i = 0;
do { /* generate digits in reverse order */
s[i++] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
if (sign < 0)
s[i++] = '-';
s[i] = '\0';
reverse(s);
}
反向()
只是反转的字符串。
这篇关于ANSI C,整串没有可变参数的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文