SPRINTF in shell scripting?

In Bash: var=$(printf ‘FILE=_%s_%s.dat’ “$val1” “$val2”) or, the equivalent, and closer to sprintf: printf -v var ‘FILE=_%s_%s.dat’ “$val1” “$val2” If your variables contain decimal values with leading zeros, you can remove the leading zeros: val1=008; val2=02 var=$(printf ‘FILE=_%d_%d.dat’ $((10#$val1)) $((10#$val2))) or printf -v var ‘FILE=_%d_%d.dat’ $((10#$val1)) $((10#$val2)) The $((10#$val1)) coerces the value into base 10 … Read more

Scanf/Printf double variable C

For variable argument functions like printf and scanf, the arguments are promoted, for example, any smaller integer types are promoted to int, float is promoted to double. scanf takes parameters of pointers, so the promotion rule takes no effect. It must use %f for float* and %lf for double*. printf will never see a float … Read more

How does printf and co differentiate between float and double

It doesn’t differentiate. It’s not possible to receive a float as a vararg: any float argument that you provide is first promoted to double. 6.5.2.2/6 defines “default argument promotions”, and /7 states that default argument promotions are applied to “trailing arguments”, that is varargs denoted by …. how does it work for scanfs/sscanf? The %f … Read more

F# printf string

That’s because the format parameter is not actually a string. It’s TextWriterFormat<‘T> and the F# compiler converts the string format into that type. But it doesn’t work on string variables, because the compiler can’t convert the string to TextWriterFormat<‘T> at runtime. If you want to print the content of the variable, you shouldn’t even try … Read more