如何将整数转换为ASCII字符? [英] How to convert an integer to ASCII character ?

查看:134
本文介绍了如何将整数转换为ASCII字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将整数值转换为ASCII最简单的方法

字符格式是什么?

我尝试使用sprintf()。它有效。

还有其他办法吗?


目标::

我想转换一个整数值3,写入字符串缓冲区。


我做了什么:

.....

.... 。

char myStr [];

int myInt = 3;

sprintf(myStr,%d,myInt);

.....

.....


请评论。

What is the most easiest way to convert an integer value to ASCII
character format ?
I tried with sprintf(). It works.
Is there any other way to do that ?

Objective::
I like to convert an integer value of 3 and write into a string buffer.

What I did:
.....
.....
char myStr[];
int myInt = 3;
sprintf(myStr, %d,myInt);
.....
.....

Please comment.

推荐答案

ak ********** **** @gmail.com 写道:
将整数值转换为ASCII
字符格式最简单的方法是什么?
我试过用sprintf ()。它有效。
有没有其他方法可以做到这一点?

目标::
我喜欢转换整数值3并写入字符串缓冲区。

我做了什么:
....
....
char myStr [];
int myInt = 3;
sprintf(myStr ,%d,myInt);
....
....

请评论。
What is the most easiest way to convert an integer value to ASCII
character format ?
I tried with sprintf(). It works.
Is there any other way to do that ?

Objective::
I like to convert an integer value of 3 and write into a string buffer.

What I did:
....
....
char myStr[];
int myInt = 3;
sprintf(myStr, %d,myInt);
....
....

Please comment.




#define DIGILEN log10(MAX_INT)+2


char buf [DIGILEN];

sprintf(buf,"%d",int_var);


Xavier



#define DIGILEN log10 (MAX_INT) +2

char buf[DIGILEN];
sprintf(buf, "%d", int_var);

Xavier


serrand写道:
serrand wrote:
ak ************** @ gmail.com 写道:
ak**************@gmail.com wrote:
将整数值转换为ASCII
字符格式最简单的方法是什么?
我尝试使用sprintf()。它有效。
有没有其他方法可以做到这一点?

目标::
我喜欢转换整数值3并写入字符串缓冲区。

我做了什么:
....
....
char myStr [];
int myInt = 3;
sprintf(myStr ,%d,myInt);
....
....

请评论。
What is the most easiest way to convert an integer value to ASCII
character format ?
I tried with sprintf(). It works.
Is there any other way to do that ?

Objective::
I like to convert an integer value of 3 and write into a string buffer.

What I did:
....
....
char myStr[];
int myInt = 3;
sprintf(myStr, %d,myInt);
....
....

Please comment.



#define DIGILEN log10 (MAX_INT)+2

char buf [DIGILEN];
sprintf(buf,"%d",int_var);

Xavier



#define DIGILEN log10 (MAX_INT) +2

char buf[DIGILEN];
sprintf(buf, "%d", int_var);

Xavier




oops ...抱歉


#define DIGILEN(int)(log10(MAX_INT)+3)


你的方式似乎是最简单的...


sprintf正在做与printf相同的工作:在stdin的wheras printf输出

sprintf输出在它的第一个参数中,它必须是一个分配的字符串


Xavier



oops... sorry

#define DIGILEN (int)(log10 (MAX_INT) +3)

Your way seems to be the simpliest...

sprintf is doing the same job as printf : wheras printf outputs in stdin
sprintf outputs in its first argument, which have to be an allocated string

Xavier


也许itoa可以使用。但它不是标准功能。

Maybe itoa could be used. But it''s not a standard function.


这篇关于如何将整数转换为ASCII字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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