我怎样才能从数据生成器datapoint*25+65
中获取像a这样的单个字符,但是我想进入str = abcdefg
(与哪个字母无关)?datapoint
创建一个介于0.0和1.0之间的值。单字符程序:
char str;
for(int n; n<60; n++)
{
str=datapoint*25+65;
str++;
}
str = '/0';
问题我不知道如何通过这种设置获得像abcd这样的char字符串,而不仅仅是像in in str这样的单个字母。
试试这个:
char str[60 + 1]; /* Make target LARGE enough. */
char * p = str; /* Get at pointer to the target's 1st element. */
for(int n = 0; /* INITIALISE counter. */
n<60;
n++)
{
*p = datapoint*25+65; /* Store value by DE-referencing the pointer before
assigning the value to where it points. */
p++; /* Increment pointer to point to next element in target. */
}
*p = '\0'; /* Apply `0`-terminator using octal notation,
mind the angle of the slash! */
puts(str); /* Print the result to the console, note that it might (partly) be
unprintable, depending on the value of datapoint. */
不使用指向当前元素的指针但使用索引的替代方法:
char str[60 + 1]; /* Make target LARGE enough. */
for(int n = 0; /* INITIALISE counter. */
n<60;
n++)
{
str[n] = datapoint*25+65; /* Store value to the n-th element. */
}
str[n] = '\0'; /* Apply `0`-terminator using octal notation,
mind the angle of the slash! */
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句