source: issm/trunk-jpl/src/c/shared/Exceptions/exprintf.cpp@ 12438

Last change on this file since 12438 was 12438, checked in by Mathieu Morlighem, 13 years ago

Back to normal

File size: 986 bytes
RevLine 
[1]1/*!\file: exprintf
2 * \brief this is a modification of the sprintf function.
3 * Instead of returning an int, it will return the char* itself.
4 * The advantage is to be able to do things like:
[3570]5 * ErrorException(exprintf("%s%i\n","test failed for id:",id));
[1]6 */
7
8
[9320]9#include <stdarg.h>
10#include <stdio.h>
[12438]11#include "../Alloc/alloc.h"
[1]12
[11199]13char* exprintf(const char* format,...){
[1]14
15 /*returned string: */
16 char* string=NULL;
17
18 /*Assum nobody will print more that 1024 characters!*/
[12438]19 string=(char*)xmalloc(1024*sizeof(char));//assume that nobody will print more than 1024 characters at once.
[1]20
21 //variable list of arguments
22 va_list ap;
23
24 //First use vsprintf to get the whole input string.
25 va_start(ap,format);
26 vsprintf(string,format,ap); //printf style coding
27 va_end(ap);
28
29 return string;
30}
Note: See TracBrowser for help on using the repository browser.