windows C++ compiler option to link user define printf

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mant
    New Member
    • Mar 2008
    • 6

    windows C++ compiler option to link user define printf

    Hi,
    I have rewritten a printf function according to my usage and I want call my printf function instead the standard printf function during my project execution.
    Can anybody tell me what is the windows C++ compiler option in Visual studio 2005, so that I can tell the windows compiler to use my printf function.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You don't need one. If a function exists in both your code and the library the linker should default to using the code you provide.

    Comment

    • Mant
      New Member
      • Mar 2008
      • 6

      #3
      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(forma t, __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.

      Comment

      Working...