putc()                   Write a Character to Stream
 
 #include   <stdio.h>
 
 putc(c,stream);                         The character written
 char       c;                           Character to be written
 FILE       *stream;                     Pointer to the file stream
 
    putc() is a macro that writes a single character 'c' to the output
    'stream' at the current position.
 
    Returns:    If successful, putc() returns the character written.
                putc() returns the value of EOF to indicate an error.
                Since EOF is a legitimate integer value, ferror() should
                be used to detect errors on the given 'stream'.
 
      Notes:    putc() performs the same operation as fputc(), but putc()
                is a macro, while fputc() is a function.
 
  -------------------------------- Example ---------------------------------
 
    This example writes the letters of the alphabet to a file, checks for
    a write error, then closes the file.
 
         #include <stdio.h>
 
         FILE *out;
         int x;
 
         main()
         {
             if ((in = fopen("alph.dat","w+")) != NULL) {
                for (x = 65; x < 91; x++) {
                    putc(x,in);
                    if(ferror(in))
                       printf("write error");
                 }
                 fclose(in);
              }
          }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster