TGC Codebase Backup



Formatted text output by San

16th Sep 2011 7:33
Summary

Text output functions that format input parameters according to format string.



Description

Text output functions that format input parameters according to format string.

Every function takes format string as a parameter and zero or more parameters to format.

Example:

float f = 123.456f;
int i = 254; // in hex is equal to 0xFE
char s[] = "Hi";
dbPrintf("%5.1f %d", f, i);
dbPrintf("%07.2f %08x %s", f, i, s);

will output to screen:
123.4 254
0123.45 000000FE Hi

For more information on formatting, search desription of "printf" function.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    #include "stdio.h"
#include "stdlib.h"

void dbPrintf(char * format, ...){
	char buf[256];
	va_list args;
	va_start(args, format);
	vsprintf(buf,format, args);
	dbPrint(buf);
	va_end(args);
}

void dbTextf(int x, int y, char * format, ...){
	char buf[256];
	va_list args;
	va_start(args, format);
	vsprintf(buf, format, args);
	dbText(x,y,buf);
	va_end(args);
}

void dbCenterTextf(int x, int y, char * format, ...){
	char buf[256];
	va_list args;
	va_start(args, format);
	vsprintf(buf, format, args);
	dbCenterText(x,y,buf);
	va_end(args);
}