Page 1 of 1
escape % in printf
Posted: Wed Oct 22, 2014 11:59 am
by pfortier
The following webpage
http://www.mekong.net/tech/printf.htm indicates that the format specifier %% will print one % but in hoc it prints 2 of them. So printf("aaa %%g bbb") will print:
aaa %%g bbb
If this is a deviation from the standard, could it be fixed?
Escaping backslashes works well, so printf("aaa %%g bbb\\n") will print:
aaa %%g bbb\n
Re: escape % in printf
Posted: Thu Oct 23, 2014 1:59 am
by hines
The fix is at
http://www.neuron.yale.edu/hg/neuron/nr ... 3444e22186
This fix was applied to the trunk (NEURON -- VERSION 7.4) and NEURON -- Release 7.3 continues to have the old behavior. Consider
Code: Select all
$ cat temp.hoc
printf("%%\n")
printf("abc%%def\n")
printf("%\n")
printf("abc%def", 2)
printf("abc%def")
The 7.3 gives
Code: Select all
%%
3
abc%%def
9
%
2
abc2ef 6
nrniv: printf not enough arguments
And 7.4 with the fix gives
Code: Select all
%
2
abc%def
8
%
2
abc2ef 6
nrniv: printf not enough arguments
Re: escape % in printf
Posted: Wed Nov 05, 2014 1:20 am
by hines
Sorry. I botched the previous fix which introduced much more serious problems. See:
http://www.neuron.yale.edu/hg/neuron/nr ... 8d1dbd1346