PDA

Click to See Complete Forum and Search --> : Convert integer/long to a string???


Warmaster199
Mar 7th, 2001, 03:29 PM
I have made a function for displaying text basing the coordinates on a given XY point:

void xytext(int x, int y, char *text)
{
move_to(x,y); /*move graphics device to x,y */
plots(text); /*plots the text string */
}

This will plot the given text to a given point. This is intended for powerc(you can use another compiler) or any compiler that doesn't have the function outtextxy();

Here is my problem: I would like to turn an integer so I can put it into a string, to display it using this function. I'm not good with strings, so can you tell me how I could add that string(converted int) to the end of another string(a phrase), so I can do something like this:

"Mouse X = " + (Interger(say 77) to string)
"Mouse X = " + "77"
"Mouse X = 77"

You get it? Please help me on this. It's EXTREMELY IMPORTANT!!!

parksie
Mar 7th, 2001, 04:08 PM
char buf[40];
itoa(number, buf, 10);

Warmaster199
Mar 7th, 2001, 04:26 PM
Thanks, Parksie!!!

Now how would I add that to the end of a string? (add 2 strings into 1)

Cybrg641
Mar 7th, 2001, 04:36 PM
Use the "strcat" function.


.
.
.
char buff[10] = "Hello ";
char buff2[10] = "world!";

strcat(buff, buff2);
.
.
.

parksie
Mar 7th, 2001, 04:39 PM
Also, sprintf should help here:

char buf[100];

sprintf(buf, "Pos: (%d, %d)", xpos, ypos);

Warmaster199
Mar 7th, 2001, 04:59 PM
OK, That works. Now, I try to switch into a mode using interrupts. This causes my function to not work. Any ideas??? Does anyone have a substitute for my function that will work?

parksie
Mar 7th, 2001, 05:03 PM
I think you need to restore the interrupt state after changing...not totally sure...it's just what I remembered from browsing that VBE documentation ages ago.

Warmaster199
Mar 7th, 2001, 05:12 PM
You mean VESA? I was using those VBE modes. Can you figure out how to restore the interrupt states? I'll try as well. Thanks

Warmaster199
Mar 9th, 2001, 03:36 PM
Ok... Maybe the PowerC print functions aren't good enough. Does anyone know the source code for outtextxy(int x, int y, char *text); , or a similar function? This is higher priority than my thread's actual topic. Please help...