__LINE__
will give you the line on which it is displayed, the line is always .
To do this, you need to pass __LINE__
as a separate parameter.
#include <stdio.h> void err (char *msg, int line) { printf ("%s : %d" , msg , line); } int main ( int argc , char **argv ) { err("fail..", __LINE__); return 0; }
An even better way to do this is to define a call to a method such as a macro, for example:
#define PRINTERR(msg) err((msg), __LINE__)
source share