On Wed, Aug 13, 2014 at 9:39 AM, Allin Cottrell <cottrell(a)wfu.edu> wrote:
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.
An update on this. The form of the sprintf() function that was described in the
hansl primer was something that Jack and I had discussed, but never finalized.
On reflection it is a more useful form than the one I outlined above. In CVS I
have therefore switched to the syntax that you were trying to use, where the
function returns the constructed string:
string sprintf(format, args)
This is now documented in the Function Reference.
Allin