Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » how to use fprintf in ALLEGRO_FILE?

This thread is locked; no one can reply to it. rss feed Print
how to use fprintf in ALLEGRO_FILE?
vkensou
Member #15,546
March 2014

i did not find some methods like al_fprintf().

and how to use fprintf?

Arthur Kalliokoski
Second in Command
February 2005
avatar

vkensou said:

how to use fprintf

I assume you already know how to use printf.

You simply add the stream as the first parameter to fprintf().

If you said

printf("Hello, world!\n");

it'd be the same as

fprintf(stdout,"Hello, world!\n");

but you can substitute some text file pointer for stdout, or stderr so redirection won't hide errors printed to console etc.

They all watch too much MSNBC... they get ideas.

LennyLen
Member #5,313
December 2004
avatar

You simply add the stream as the first parameter to fprintf().

fprintf() expects a FILE, not an ALLEGRO_FILE. It might work anyway, but I wouldn't rely on it.

You can use snprintf() to create a formatted string, and then use al_puts() to write it to the file.

Thomas Fjellstrom
Member #476
June 2000
avatar

Hm, that might be a bit of an oversight. Might want to add a al_fprintf and similar to the api

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

beoran
Member #12,636
March 2011

Yes, that would be useful and nice to have, so I added it to the roadmap on the wiki. This is really not that hard to implement, so if anyone feels they want to do this, please do so and post your patch here or on the mailing list. :)

Elias
Member #358
May 2000

u = al_ustr_newf(fmt, "%s", "blah");
al_fputs(f, al_cstr(u));
al_ustr_free(u);

--
"Either help out or stop whining" - Evert

Go to: