putc: writes a character to the output stream : putc « stdio.h « C / ANSI-C






putc: writes a character to the output stream


    

//Header file:     #include <stdio.h>  
//Declaration:     int putc(int ch, FILE *stream); 
//Return:          returns the character written on success and EOF on error. 


  

  #include <stdio.h>
  #include <stdlib.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);
    }
  }

           
       








Related examples in the same category