Output a single character with putchar() function - C Data Type

C examples for Data Type:char

Introduction

The putchar() function that complements getchar() is declared in stdio.h.

It has the prototype:

int putchar(int c);

The function outputs a single character, c, to stdout and returns the character that was displayed.

Demo Code

#include <stdio.h>

int main(void) {
   int i = 0;/*from  w ww . j a  v  a  2s.  c  om*/
   char string[20] = "this is a test";
   while (string[i] != '\0') {
      if (string[i] != '\n')
         putchar(string[i]);
      ++i;
   }
}

Result


Related Tutorials