Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between putchar(), putch(), fputchar()?

Tags:

c

I read these concepts from the book and I searched a lot on internet too but there is no good definition and explanation available. Everywhere it is just written that putch(), putchar() and fputchar() work in the same way and are used to print character to console but I think there must be some different between them ?

like image 268
Vikas Verma Avatar asked Nov 14 '13 15:11

Vikas Verma


2 Answers

This simple manual page certainly describes the differences, albeit tersely:

  • fputc() writes the character c, cast to an unsigned char, to stream.
  • putc() is equivalent to fputc() except that it may be implemented as a macro which evaluates stream more than once.
  • putchar(c) is equivalent to putc(c, stdout).
like image 84
unwind Avatar answered Oct 25 '22 13:10

unwind


From here:

int fputc(int c, FILE *stream);

int putc(int c, FILE *stream);

int putchar(int c);

The fputc() function writes the character c (converted to an ``unsigned char'') to the output stream pointed to by stream.

The putc() macro acts essentially identically to fputc(), but is a macro that expands in-line. It may evaluate stream more than once, so arguments given to putc() should not be expressions with potential side effects.

The putchar() function is identical to putc() with an output stream of stdout.

like image 45
trojanfoe Avatar answered Oct 25 '22 13:10

trojanfoe