![]() |
| | #1 |
| Registered User Join Date: Jan 2003
Posts: 47
| Core Dump with Variable Arguments Code: I have written the following code which accepts variable arguments:
void dprintf(FILE *fp,char *fmt,...)
{
char OldMsg[BUFSIZ];
va_list lArgs;
if(fmt && *fmt)
{
fmt[strlen(fmt)-1]='\0'; /* Remove ending \n */
va_start(lArgs, fmt);
vsprintf(OldMsg, fmt, lArgs);
va_end(lArgs);
fprintf(fp, "%s at %s_%02d\n",
OldMsg, Run.date, Run.hour);
}
}
I am calling the function as follows:
dprintf(flog,"\t%s(%s): Unable to insert node\n",
program_name, sccs_ver);
|
| penney is offline | |
| | #2 |
| Registered User Join Date: Jan 2003
Posts: 47
| Thank you very much. I did realize that it throws away the last char unconditionally. The whole reason I created the routine was because their were a million fprintf's in the program and I needed a way to easily add a date/time stamp to the end of the messages without having to do a bunch of manual work. I verified ahead of time that all the previous calls ended in a \n and will always end that way. I was so focused on something being wrong with the var message part I overlooked the const pointer issue - so thank you all very much. |
| penney is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help: Compiler is trying to convert identical variable arguments .c and .h files | Phanixis | Linux Programming | 4 | 10-08-2007 11:47 AM |
| core dump.... | Shogun | C Programming | 1 | 06-03-2003 08:41 AM |
| core dump | lonbgeach | C Programming | 1 | 04-07-2003 03:34 PM |
| problem with strtok & core dump | razza | Linux Programming | 4 | 04-24-2002 04:56 PM |
| segmentation core dump - need help | knight101 | C++ Programming | 1 | 11-26-2001 04:43 PM |