cputchar

What's the difference between putch() and putchar()?


Okay so, I'm pretty new to C.

I've been trying to figure out what exactly is the difference between putch() and putchar()? I tried googling my answers but all I got was the same copy-pasted-like message that said:

putchar(): This function is used to print one character on the screen, and this may be any character from C character set (i.e it may be printable or non printable characters).

putch(): The putch() function is used to display all alphanumeric characters through the standard output device like monitor. this function display single character at a time.

As English isn't my first language I'm kinda lost. Are there non printable characters in C? If so, what are they? And why can't putch produce the same results?

I've tried googling the C character set and all of the alphanumeric characters there are, but as much as my testing went, there wasn't really anything that one function could print and the other couldn't.

Anyways, I'm kind of lost.

Could anyone help me out? thanks!

TLDR; what can putchar() do that putch() can't? (or the opposite or something idk)

dunno, hoped there would be a visible difference between the two but can't seem to find it.


Solution

  • putchar() is a standard function, possibly implemented as a macro, defined in <stdio.h> to output a single byte to the standard output stream (stdout).

    putch() is a non standard function available on some legacy systems, originally implemented on MS/DOS as a way to output characters to the screen directly, bypassing the standard streams buffering scheme. This function is mostly obsolete, don't use it.

    Output via stdout to a terminal is line buffered by default on most systems, so as long as your output ends with a newline, it will appear on the screen without further delay. If you need output to be flushed in the absence of a newline, use fflush(stdout) to force the stream buffered contents to be written to the terminal.