添加int值在C字符数组 [英] Adding int value to a char array in C

查看:94
本文介绍了添加int值在C字符数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在字符阵列添加一个 INT 值。这意味着,如果我有一个 1 ,我想重新present它像 1

I would like to add an int value in a char array. meaning if I have a 1, I would like to represent it like '1'.

我看到一个公式来做到这一点之前得到它的ASCII code。我有一个有限的编译器对C工作,所以我没有奢侈到使用像函数的sprintf()或他人。它必须是在我必须实现一个方程式的形式。任何人可以帮助我这一点。

I have seen an equation to do this before to get the ASCII code of it. am working with a limited compiler for C so I don't have the luxury to use functions like sprintf() or others. it has to be in the form of an equation that I must implement. Can anybody help me with that.

例如想什么,我做的。

char array[2];
char array[0] = 1 * (equation);

然后数组[0] 应该有值1。

推荐答案

如果你使用值范围0-9时,您可以使用

If you're working with values in range 0-9, you can use

array[0] = 1 + '0';

这会给你的字符重新presentation( 1 )<$ C $的C> INT 值( 1 )。

This will give you the char representation ('1')of int values (1).

这篇关于添加int值在C字符数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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