我实际上想延迟打印文本的每个字符(char 数组的每个索引);因此,我正在尝试开发一个自定义函数,该函数采用 x 坐标、y 坐标、x 增量和 y 增量、延迟和指向outtextxy
Turbo C中使用的文本字符数组的指针。
这是我的代码:
void printing(int x, int y, int xinc, int yinc, int d, char word[50]){
int i;
int size = strlen(word);
setcolor(LIGHTGREEN);
for(i = 0; i < size; i++){
outtextxy(x,y,word[i]);
}
x += xinc;
y += yinc;
delay(d);
}
但这每次都会给我一个错误:
在调用“outtextxy”时,参数“__textstring”中的类型不匹配
我该如何解决这个问题?
该outtextxy
函数的第三个参数必须是指向以空字符结尾的字符串(或char
数组)的指针,但您传递的是单个字符。
作为一个快速修复,您可以只声明一个 2 字符数组(一个用于 nul 终止符)并char
在每次调用之前将您的单曲复制到该数组中:
void printing(int x, int y, int xinc, int yinc, int d, char word[50])
{
int i;
int size = strlen(word);
setcolor(LIGHTGREEN);
for (i = 0; i < size; i++) {
char text[2] = { word[i], 0 }; // This character plus nul terminator
outtextxy(x, y, text); // Array "decays" to a pointer to first char
}
x += xinc;
y += yinc;
delay(d);
}
但是,在 Turbo-C 图形库中可能有不同的函数,例如putcharxy(int x, int y, char c)
,您可以使用它来代替给定坐标处的单个字符。(我无权访问该库或任何权威的在线文档,尽管此源中似乎没有声明这样的函数。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句