Hello All,
I´m trying to write a function to write some information into a log file and possible some debuging info too.
I have writen:
Code:
int WriteLog(char *msg, int deb)
{
FILE *logfile;
char buff[80];
logfile = fopen("logfile.txt","a");
if(DEBUG) {
printf("[debug] "); printf("%s\n",msg);
sprintf(buff,"%s%s\n","[debug] ",msg);
fprintf(logfile,buff);
fprintf(logfile,"\n");
}
else {
if(deb == 1) {
printf("%s\n",msg);
}
fprintf(logfile,msg);
fprintf(logfile,"\n");
}
fclose(logfile);
return 1;
}
main has this line I want to print to log:
Code:
main()
{
char bu[]="192.168.0.1";
printf(">> database: ServerIP: (%s)\n",bu);
//WriteLog(?????,1);
}
I wanted pass this to the WriteLog function but I realy don´t want to use some thing like sprintf...
As I´m newbie in C programing, can any guru help me ? Is there a smart way of doing this ?
Thanks,