He allowed him the C statement but kept it simplified - a good compromise I think.
Quite surprising, though, at least as Wikipedia claims¹, this (except for the lack of "\n") was the exact "hello world" code from the first edition of K&R.
____
¹) http://en.wikipedia.org/wiki/C_(programming_language)#.22Hel... and I don't have any copy of the first edition.
printf("goodbye, Dennis");
would give $ ./goodbye
goodbye, Dennis$
What you want is to add a newline ('\n') at the end: printf("goodbye, Dennis\n");
Now you get $ ./goodbye
goodbye, Dennis
$
That's why the canonical "hello, world" program contains the line printf("hello, world\n");Flushing doesn't automatically add newlines for you in C. It flushes the buffers you gave it, it doesn't make new stuff up to print out along with your buffers.
#include <stdio.h>
int main(int c, char **v) {
printf("Hello\nJello");
while(1) ;
return 0;
}Also, using printf() for debugging? In 2011? I seriously hope you guys don't do this.
OK, I'll bite. I haven't done any serious straight up C programming in over a decade, and yes, I used a lot of printf for debugging back then. What's the best way to debug C programs now? (I imagine printf wasn't the best way to debug programs when I was writing C, either.) A different logging library? gdb?
If you're dumping printf()s all over the place to see exactly what flow your program is taking at runtime, you're better off just setting a breakpoint or two and using a debugger to quickly step through it.