Forums > MaxMSP

sprintf question

January 31, 2010 | 1:36 am

Why does [sprintf string%1i string%1i] evaluate to [string$1 string0]? Similarly [sprintf string%1i string%2i] evaluates to [string$1 string $2]. I figured out I could fix it by doing [sprintf string%1i string%.2i] to get the leading zero, but I don’t understand what’s going on here.


January 31, 2010 | 2:39 am

I can’t reproduce that behaviour. What values are you sending in to the [sprintf] object? To get a leading zero use something like [sprintf symout %04i] where the 4 sets how much padding you want. You can use [sprintf symout %.4f] to apply the padding after a decimal place.

lh


January 31, 2010 | 9:53 am

Unlike expr, sprintf does not require variables to be designated to specific inlets. Each new variable will create an inlet and the order of inlets is identical to the order of variables. In your specific example, the number 1 in string%1i does not do anything as it is not part of the definition of printf.

_
johan


January 31, 2010 | 9:35 pm

Thanks, Johan. It works fine if I just remove the numbers and send the integer to each inlet.


Viewing 4 posts - 1 through 4 (of 4 total)