C putc() function

C library function - putc()

The putc() function is used to convert character to unsigned character and then writes character to the output stream at the current position.


int putc(int char, FILE *stream)


Name Description Required /Optional
char Character write to the output stream. Required
stream Identifies an address for a file descriptor, which is an area of memory associated with an input or output stream. Required

Return value

  • Upon successful completion, putc() shall return the value it has written.
  • Otherwise, it shall return EOF, the error indicator for the stream shall be set, and errno shall be set to indicate the error.

Example: putc() function

In this example, the contents of a buffer are written to a data stream

#include <stdio.h>
#include <string.h>
#define  LEN_STR 80
int main(void)
   FILE *stream = stdout;
   int i, C;
   char buffer[LEN_STR + 1] = "C Programming.";
   for ( i = 0;
        (i < strlen(buffer)) && ((C = putc(buffer[i], stream)) != EOF);


C Programming.

C Programming Code Editor:

Previous C Programming: C getc()
Next C Programming: C putchar()

Share this Tutorial / Exercise on : Facebook and Twitter

C Programming: Tips of the Day

What's an object file in C?

An object file is the real output from the compilation phase. It's mostly machine code, but has info that allows a linker to see what symbols are in it as well as symbols it requires in order to work. (For reference, "symbols" are basically names of global objects, functions, etc.)

A linker takes all these object files and combines them to form one executable (assuming that it can, i.e.: that there aren't any duplicate or undefined symbols). A lot of compilers will do this for you (read: they run the linker on their own) if you don't tell them to "just compile" using command-line options. (-c is a common "just compile; don't link" option.)

Ref : https://bit.ly/3CbzF8M