I have a project written in C if I build it using Borland C++ compiler things are going on fine and if I build using Visual Studio compiler its not.
The scenario is,
I have a project which is in C, in one of the file I have redefined the printf function. Below
// This printf will write on to a file instead on stdout
// myfile.c
#define printf(format, ...) \
perprintf(format, __VA_ARGS__)
int perprintf (const char *format, ...)
{
va_list args;
FILE* fptr;
va_start (args, format);
fptr = fopen("C://TestPrintf.txt", "at");
vfprintf(fptr, format, args);
fflush(fptr);
va_end(args);
fclose(fptr);
return 1;
}
//outsidefile.c
printf(msg);
If I call printf in the same file then its calling my printf function, printf's written outside this file are unable to call this printf function. And I expect my printf function to be called outside that file as well.
So I was wondering how to tell the outside files that the printf function is overrriden? and to use this printf at any point of time.