Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>putc() write a character to stream (macro)</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 putc()                  Write a Character to Stream (Macro)

 #include   <stdio.h>

 int putc(c,stream);
 int        c;                           Character to be written
 FILE       *stream;                     Pointer to the FILE stream

    putc() is a macro that writes one 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.
                EOF is a legitimate integer value, however, so 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);
                }
           }


See Also: fputc() getc() getchar()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson