DPRG
DPRG List  



[DPRG] More C programming help needed - variable arguments

Subject: [DPRG] More C programming help needed - variable arguments
From: Clay Timmons ctimmons at cadence.com
Date: Thu Sep 9 20:27:37 CDT 2004


The __DATE__ macro does get expanded by the pre-processor, Thanks Shaun.

Now I have one more question.  I want the robot to log all of it's
messages to both the standard output and to a file.

Something like this ...

printf("Starting to search for cans"); 
fprintf(LOGFILE,"Starting to search for cans");

Now I don't really want to duplicate every single print statement in my
code as shown.  I would like to have my own function which would write
to both the standard output and the LOGFILE.  Something like ...

log("Starting to search for cans");

I've written this function and it works fine.  (LOGFILE is a global)

void log(message)
  char *message;
{
   printf("%s",message);
   fprintf(LOGFILE,"%s",message);
}

Now here is where I need help.  I want the log function to have full
printf type functionality.  Something like

log("I've detected a CAN  range: %d   bearing: %d",cdist,angle);


Does anyone know how to write the log function to do this?

I'm a bit rusty on those variable arguments.

I also plan to have the log function timestamp every message so that I
have an exact record of each robot run. 

Thanks,

-Clay-






More information about the DPRG mailing list