working quickly with strings: need char*

Dear all,

I am writing a program for certain rather heavy mathematical computations and I use WINAPI functions for graphical output for debug purposes.

I want to output some internal variables on the screen for easier debug.

At the moment I use the following (working) code. I find it extremely clumsy and long. How can I rewrite it nicely? Thanks in advance for your advice!

/*code follows*/

void drawtext(int X1, int Y1, char* text, int length);

//...
//code I would like written better:
{
char text[20]="#Simplices:";
::_itoa(output.size,text+11,10);
drawtext(0,0,text,20);
char text2[20]="Direction#:";
::_itoa(directionIndex,text2+11,10);
drawtext(0,15,text2,20);
}


Last edited on
1
2
3
4
5
6
char buffer[100] = {0};

sprintf(buffer, "#Simplices:%i", output);
drawText(0,0,buffer, strlen(buffer));
sprintf(buffer, "#Direction:%i", directionIndex);
drawText(0,0,buffer, strlen(buffer));


Note: sprintf is only really good for debugging. It won't prevent buffer overflows if your output exceeds 100chars etc.
Thanks a lot! Worked out perfectly :)
Topic archived. No new replies allowed.