help on sprintf

Linux specific forum
frederic
User
User
Posts: 56
Joined: Thu Jan 05, 2006 11:22 pm

help on sprintf

Post by frederic »

Hello, i've an error with this code and i don't understand why.
With 1 arg, it's working, and with 2 args no :(
Any idea ?

Code: Select all

;===============================
; WORKING
text$  = ""

format$ = "nombre : %d"

sprintf_( text$, format$, 5)

Debug text$
;===============================
; NOT WORKING
format$ = "nombre : %d, nombre 2 : %d"

sprintf_( text$, format$, 5, 6)

Debug text$
;===============================
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

I don't think the PureBasic Compiler has support for var_args, so that might not work, however I guess you could use Inline ASM to work around this,
Fred
Administrator
Administrator
Posts: 18351
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

yes, variable arguments aren't supported in PB. RThe easiest workaround is to use the vsnprintf_() function which takes an array in parameter. But why do you need such a function in PureBasic, while you have many build-in string fonctions ?
michaeled314
Enthusiast
Enthusiast
Posts: 340
Joined: Tue Apr 24, 2007 11:14 pm

Post by michaeled314 »

Or you can call a function from a library
frederic
User
User
Posts: 56
Joined: Thu Jan 05, 2006 11:22 pm

Post by frederic »

ok thanks for the precision about pbcompiler.

Why i need this function ? Just to try :) Lot of codes are for win32 api, so i'm doing some research with linux functions because i'm not on windows.
Post Reply