I made this printf command which is very similar to the C++ printf command:
#constant printf call function name "_printf",
function _printf()
handle = open arglist()
format as string
result as string
format = arglist string$(handle)
format_len = fast len(format)
result = ""
for i = 1 to format_len
c$ = mid$(format,i)
if c$ = "%"
inc i
c$ = mid$(format,i)
select c$
case "c"
result = result + chr$(arglist integer(handle))
endcase
case "i"
result = result + str$(arglist integer(handle))
endcase
case "f"
result = result + str$(arglist float(handle))
endcase
case "d"
result = result + str$(arglist double float(handle))
endcase
case "o"
result = result + decimal to base(arglist integer(handle),8)
endcase
case "s"
result = result + arglist string$(handle)
endcase
case "u"
result = result + str$(arglist dword(handle))
endcase
case "x"
result = result + fast lower$(decimal to base(arglist integer(handle),16))
endcase
case "X"
result = result + fast upper$(decimal to base(arglist integer(handle),16))
endcase
case "%"
result = result + "%"
endcase
endselect
else
result = result + c$;
endif
next i
print result
endfunction
Just put that in your code somewhere, and you can call it like this:
printf "Test %i, a formatted %s and a %character",1,"string",asc("c")
The string is printed out normally until it finds a % sign. The character following it decides what happens next:
c -> The character defined by a character code is printed out
i -> An integer is printed out
f -> A float is printed out
d -> A double float is printed out
o -> An integer is printed out in base 8
s -> A string is printed out
u -> A dword is printed out
x -> An integer is printed out in lower-case hexadecimal
X -> An integer is printed out in upper-case hexadecimal
% -> A percent sign is printed out
The command takes a variable number of arguments, and you should make sure that the parameters you pass in match up with the format characters within the string (if the first formatting character is 'i', the first argument after the formatting string should be an integer, etc.)
Enjoy