Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


A pure C problem: function with undefined arguments...

This topic is 5284 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello there! Here is my problem: I would like to create a function which looks like this: void logMessage(const char *message, ...){ // Opening a file called "Log.txt" FILE *file = fopen("log.log", "at"); // Forwarding all the arguments of the function fprintf(file, message, ...); // ... then closing file ..... } Basically, the function''s role is to update a ''Log.txt'' text file with ''printf-like'' arguments. The point is: how to forward the function arguments into the ''fprintf'' function? I''ve not been able to find an answer after 2 days of coding!!! Maybe there''s no solution after all !?!? ...... we never know ...... ^^'' "A bientot!"

Share this post

Link to post
Share on other sites

void logMessage(const char *message, ...){

FILE *file = fopen("log.log", "at");

va_list va;
va_start(va, message);
vfprintf(file, message, va);


Share this post

Link to post
Share on other sites
Thanks a lot for your help! IT WORKS!!! But where do these va_stuff come from? I didn't know anything about this 'stdarg.h' function...

"A bientot!"

[edited by - Ichitakasan on April 4, 2004 1:12:08 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!