title: write debug messages in c to a file?
body: <p>How can I write debug messages to file?</p>
  
  <p>I am using:</p>
  
  <pre><code>void printLog(const char* mylog)
  {
    #ifdef DEBUG
  
    FILE* pFile = fopen("mylog.txt", "a");
    fprintf(pFile, "%s\n",mylog);
    fclose(pFile);
  
    #endif
  
  }
  </code></pre>
  
  <p>But how can I write commands in order to debug?</p>
  
  <p>EDIT:</p>
  
  <p>I mean , like I know in android ,you state for example <code>Log.i("MyActivity", "MyClass.getView() — get item number " + position);</code>.</p>
  
  <p>Can I write something similar in c to a file?
  A variable maybe ,an error etc.</p>
  
  <p>I am using :  <code>gcc -g -DEBUG -o myexec myfile.c</code> </p>