Chapter Contents

Previous

Next
putchar

putchar



Write a Character to the Standard Output Stream

Portability: ISO/ANSI C conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <stdio.h>

int putchar(int c);


DESCRIPTION

putchar writes a character c to the stream stdout .


RETURN VALUE

putchar returns the character written or EOF if an error occurs.


EXAMPLE

This example writes the first line of a file to stdout :

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

main()
{
   int c;
   FILE *infile;
   char filename[60];

   puts("Enter the name of your input file:");
   memcpy(filename, "tso:", 4);
   gets(filename+4);
   infile = fopen(filename, "r");
   if (!infile){
      puts("Failed to open input file.");
      exit(EXIT_FAILURE);
   }

      /* While character is not a newline character,  */
      /*  read character from file MYFILE.            */
   while (((c = getc(infile)) != '\n') && (c != EOF))

      /* Write one character of the file to the       */
      /*  standard output; this line is written one   */
      /*  character at a time.                        */
   putchar(c);
   putchar('/n');
}


RELATED FUNCTIONS

putc


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.