将 int 转换为 Char*,给出 ascii 值 C++
你好,我正在尝试初始化一个变量 我使用 SDL 调用它,
int Score;
char Buffer[1024];
所以要显示它们,我必须将 Score 转换为 char
有了这个,我会增加分数
case SDLK_m:
Score+=1;
break;
,并使用此函数显示它,
void GetText()
{
itoa (Score,Buffer,1024);
drawString(screen,font2,0,0,"Score: ");
drawString(screen,font2,50,0,Buffer);
}
所以当我显示它时,它会像这样 0,1,2,3,4,5,6,7,8,9,a,b,c,d,e等 我希望它正常计数为 0,1,2,3,4,5,6,7,8,9,10,11 等,
那么我做错了什么?有什么想法吗?
hi im trying to intialize a variable
im calling it
int Score;
char Buffer[1024];
im using SDL so to display them i had to convert Score to char
With this im incrementing the score
case SDLK_m:
Score+=1;
break;
and im displaying this with this function
void GetText()
{
itoa (Score,Buffer,1024);
drawString(screen,font2,0,0,"Score: ");
drawString(screen,font2,50,0,Buffer);
}
so when im displaying it it goes like this
0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,etc
and i want it to normally count like 0,1,2,3,4,5,6,7,8,9,10,11,etc
so what am i doing wrong? any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
itoa 定义如下:
char * itoa ( int value, char * str, int base );
最后一个参数是基数,而不是缓冲区大小,因此在您的情况下,您需要传入
10
如下:itoa is defined as follows:
char * itoa ( int value, char * str, int base );
The last param is the base, not the buffer size, so in your case you would want to pass in
10
as follows: