Use C putc function to output character to a stream
Syntax
C putc function has the following syntax.
int putc(int ch, FILE *stream);
Header
C putc function is
from Header file stdio.h
.
Description
C putc function writes a character to the output stream.
C putc function returns the character written on success and EOF on error.
For binary mode, you can use ferror() to determine whether an error has occurred.
Example
Write character to a stream by using C putc function
#include <stdio.h>
//from w ww. j av a2 s . co m
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);
}
}