Jump to content

printf


bonassus

Recommended Posts

I'm confused about printf. I don't know c++ and so never had to use it before leaning vex. I'm wondering about all letters you can use for the arguments in the printf function. I've seen %f used for a float. %d also used for float (decimal i guess), %s for string, and %i for integer. 

the docs state: The conversion of the argument is specified by a single letter: g, f, s, d, x, c, p.

it goes on to show: 

%g, %p, %c

Print an integer float, vector, vector4, matrix3, matrix or string in "general" form.

%f, %e, %E

Print a float, vector, vector4, matrix3 or matrix in floating point form.

The first example shows 3 argument types and 7 data types. Does this mean i can use any of the listed %letter arguments with any of the data types shown? 

Link to comment
Share on other sites

generally yes ;), %d will work with most "number" types same as %f, the difference between them is mostly formatting I think.

For instance with %d, it will limit the amount of decimals in the output string, whereas %f will try to keep as many digits behind the decimal point as possible.
There are some other tricks that you could use, such as %02d. that will pad the start of the output with zeros, so you can do a more easy alpha-numeric search for example :)

personally, I never had to use anything other than %f, %d or %s.

Edited by acey195
gramarz
  • Like 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...