On Mon, 11 Aug 2014, Henrique Andrade wrote:
> I'm trying to use the sprintf as a function instead of a command and it
> is not working here at my Windows Vista withe the latest Gretl snapshot.
>
> Please take a look at the following script:
>
> <hansl>
> open australia.gdt
>
> genr time
>
> ols PAU const time
>
> matrix T = $coeff./$stderr
> scalar T_calc = abs(T[2,])
> scalar T_tab = critical(t, $T, 0.05)
>
> sprintf Test_1 "t-calculado: %f \n t-tabelado: %f", T_calc, T_tab
> print "@Test_1"
>
> string Test_2 = sprintf("t-calculado: %f \n t-tabelado: %f", T_calc, T_tab)
> print "@Test_2"
> </hansl>
Thanks for the report. The function form of sprintf is incorrectly
documented in the hansl primer. (It's not documented at all in the
Function Reference and should be considered experimental.) Anyway, if you
want to use it, the actual syntax is
scalar sprintf(stringvar, format, args)
where the scalar return value is the number of characters printed, and the
"stringvar" argument is the name of the target string. So in the context
of your script you would do
string Test_2
sprintf(Test_2, "t-calculado: %f \n t-tabelado: %f", T_calc, T_tab)
I should also say that the command-form of "sprintf" is not going away any
time soon, if ever. We'll fix the text in the primer.
Allin