putc : putc « stdio.h « C Tutorial






ItemValue
Header filestdio.h
Declarationint putc(int ch, FILE *stream);
Functionwrites a character to the output stream.
Returnreturns the character written on success and EOF on error.


For binary mode, you can use ferror() to determine whether an error has occurred.

#include <stdio.h>
 
  int main(void){
 
    FILE *fp;

    if((fp=fopen("test", "w"))==NULL) {
      printf("Cannot open file.\n");
      exit(1);
    } 
 
    char *str = "www.java2s.com";
 
    for(; *str; str++){
        putc(*str, fp);
    }
  }








22.25.putc
22.25.1.putc