将char存储到char数组中. [英] To Store char into char array.
问题描述
你们好..
拜托,帮帮我...!示例代码就是这样..
Hello Guys..
Please, Help me out of this...! The sample code is like this..
int i = 65;
char c = static_cast<char>(i); // here c stores the letter 'A'.
在我的计划中,每当我重视变化&时,我正在将整数转换为char.但是我的疑问是如何将char存储到字符数组中?
例如:i值为65,66,67,依此类推.正在转换为等效字符,例如"A","B","C"和等等,而且,我想将这些A,B,C字符存储到Character数组中..
请给我建议一些想法..
谢谢..
In my Program, Every time i value changes & Am converting integer to char. But my doubt is How do i store char into character array ?
For Example: i values are 65,66,67 and so on.. & Am converting into equivalent characters like ''A'',''B'',''C'' & so on.. And, I want to store these A,B,C characters into Character array..
Please suggest me some ideas..
Thanks..
推荐答案
#include <stdio.h>
int main()
{
const int maxItems = 10;
char myArray[maxItems], curChar;
int i;
for (i=0; i<maxItems; i++)
{
curChar = i;
curChar += 'a';
myArray[i] = curChar;
}
for (i=0; i<maxItems; i++)
{
printf("Item %d: '%c'\n", i, myArray[i]);
}
return 0;
}
不清楚,
但说明很少:
1.如果要使用数字数据设置字符值,则不需要强制转换
例如
Not Clear,
But few instruction:
1. You do not need casting if you want use numeric data to set character value
e.g.
//all of them are valid statement
char c;
c=65;
c=0x41;
c='A';
c='A'+32; // you will get 'a'
c='A';
c++; //you will get 'B'
2.要了解您需要的知识,您需要了解数组.这超出了这里的范围.
2. To understand you need you need to learn about array. It is beyond scope here.
这篇关于将char存储到char数组中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!