Sprintf

From Game Editor

Revision as of 21:07, 5 September 2008 by Asmodeus (Talk | contribs)
Jump to: navigation, search

For string variables write this:

strcpy(text, (char *)YourStringVar);

or

sprintf(text, "%s", YourStringVar);

%s is for string.

For integer and real variables the same as above, %d for an integer variable and %f for real variables.

example:

sprintf(text, "A string: %s\nAn integer: %d\nA float value: %f", "Hello!", 7, 3.4);

That changes your text to:

A string: Hello!

An integer: 7

A float value: 3.4

("\n" means new line)

Avaible escape sequences

Escape sequences are things like \n or \s.

specifer output example
c character a
d or i signed decimal integer 392
f decimal floating point 392.65
s string of characters sample
x unsigned hexadecimal integer 7fa
X unsigned hexadecimal integer (capital letters) 7FA
n new line
% puts out a per cent symbol %