Java-style println() in C
Hi,
I've been trying to create a java-style System.out.println() function in C, so that I don't have to keep writing \n at the end of every printf(), which I also keep forgetting...
I've read this thread about it:
https://cboard.cprogramming.com/c-pr...ntln-code.html
Where you concluded it not to be possible in C.
It is.
You just have to use a macro to do it:
Code:
#define println(fmt, args...) ({\
int __a = printf(fmt,args);\
printf("\n");\
++__a;\
})
It's consistent with printf() in the way that the return value is the number of total characters printed.
Hope it's helpful to others who want to do this. :)