Add newline at the end of an integer using putchar() (C programming)?

Viewed 7519

I'm new to C programming, and I'm trying to figure out how I can add a newline ("\n") after printing an int value using the putchar() function. In "The C Programming" book by K&R, they provide the script below, but all characters are printed on the same line. How can I modify the code to print one character per line?

#include <stdio.h>

void main() {
int c;

c = getchar();
while (c != EOF) {
    putchar(c);
    c = getchar();
 }
}

I know I could use printf() with something like this:

printf("%d\n", c);

But I am wondering if C programming and the putchar() function have something like:

putchar(str(c)+"\n");

Kinda the same way you would do it in, say, python. Thanks!

1 Answers
Related