Some useful defines for debugging are:
Code:
__LINE__ /* current line of the source file (<underscore><underscore>LINE<underscore><underscore>) */
__FILE__ /* current source file name */
__TIME__ /* the time this executable was compiled (string) */
__DATE__ /* the date it was compiled (string) */
__func__ /* (C99) name of the current function */
So you could have a debugging macro like this:
Code:
#include <stdio.h>
#define debug_str(s) \
printf(__FILE__ ":" __func__ "():%i: %s\n", __LINE__, s)
int main(void) {
debug_str("Before printf()");
printf("Hello, World!\n");
debug_str("After printf()");
return 0;
}
Output:
Code:
debug_str.c:main():7: Before printf()
Hello, World!
debug_str.c:main():9: After printf()
The best debugging tool, however, is a debugger. If you have Dev-C++ or GCC, then you can compile your program with -g and use GDB to debug it:
Code:
C>gcc -g -o hello.exe hello.c
C>gdb hello.exe
This is GDB version x.xx ....
(gdb) run
Hello, World!
The program exited normally.
(gdb) quit
C>
This site has a tutorial on using GDB.