Home > database >  How to pass a particular index of char array to outtextxy() function's third parameter in c
How to pass a particular index of char array to outtextxy() function's third parameter in c

Time:04-03

I actually want to print every character of the text (every index of char array) with a delay; hence, I am trying to develop a custom function which takes x co-ordinate, y co-ordinate, x increment and y increment, delay and the pointer to the char array of text using outtextxy in Turbo C.

Here's my code:

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);
}

But this gives me an error every time:

Type mismatch in parameter '__textstring' in call to 'outtextxy'

How can I solve this?

CodePudding user response:

The third parameter of the outtextxy function must be a pointer to a nul-terminated character string (or char array), but you are passing a single character.

As a quick fix, you can just declare a 2-character array (one for the nul terminator) and copy your single char into that before each call:

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);
}

However, there may be a different function, such as putcharxy(int x, int y, char c), in the Turbo-C graphics library that you can use, instead, to outpt a single character at the given coordinates. (I don't have access to that library, or any authoritative online documentation, although there doesn't appear to be such a function declared in this source.)

  • Related