有多少种方法可以将整数转换为字符串 [英] how many ways to convert a integer to a string
问题描述
尽可能多。
int i = 333;
char * s;
如何将i转换为s;
ap *********** @ gmail.com 写道:尽可能多。
int i = 333;
char * s;
如何将我转换为s;
你的问题不够明确(应该在
$ b中表示) $ b帖子的主体也是)。你想使用标准函数
(参见`sprintf`),还是在寻找不同/算法/方法?
< blockquote> ap*********** @ gmail.com 写道:< blockquote class =post_quotes>
尽可能多。
int i = 333;
char * s;
如何将i转换为s;
#include< stdlib.h>
#include< limits.h>
#include< stdio.h>
s = malloc((size_t)((sizeof(int)* CHAR_BIT - 1)/ 3.3)+ 3);
if(s!= NULL ){
sprintf(s,%d,i);
}
-
pete
ap ***********@gmail.com ??????
尽可能多。
int i = 333;
char * s;
如何将i转换为s;
另一种方法是获取每个数字从整数然后将
difit转换为它的相应char。继续将整数
除以10,直到结果为0.每个除法的剩余部分是整数最左边的数字。
>
as many as possible.
int i = 333;
char* s;
how to convert i to s;
ap***********@gmail.com wrote:as many as possible.
int i = 333;
char* s;
how to convert i to s;
Your question is not clear enough (and should have been repreated in
the body of the post as well). Do you want to use standard functions
(see `sprintf`), or are you looking for different /algorithmic/ ways?
ap***********@gmail.com wrote:
as many as possible.
int i = 333;
char* s;
how to convert i to s;
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
s = malloc((size_t)((sizeof(int) * CHAR_BIT - 1) / 3.3) + 3);
if (s != NULL) {
sprintf(s, "%d", i);
}
--
pete
ap***********@gmail.com ???é?????
as many as possible.
int i = 333;
char* s;
how to convert i to s;
Another way is to get every digit from the integer and then convert the
difit to it''s corresponding char. Just continue to divide the integer
by 10 until the result is 0. The remainder of each division is the
leftmost digit of the integer.
这篇关于有多少种方法可以将整数转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!