{{keywords>wiki library source code example reference}}
===== fputc =====
int fputc(int ch, FILE *stream);
Writes ch, to stream stream. Returns ch, or EOF on error.
===== C Sourcecode Example =====
/*
* fputc example code
* http://code-reference.com/c/stdio.h/fputc
*/
#include /* including standard library */
//#include /* uncomment this for Windows */
int main( void )
{
FILE *stream, *stream_target;
char c;
if((stream=fopen("test.txt","rb"))==NULL) {
printf("Cannot open file.\n");
return 1;
}
if((stream_target=fopen("testcopy.txt","wb"))==NULL) {
printf("Can't write to target\n");
return 1;
}
printf("copy file\n");
while((c = fgetc(stream) ) != EOF) {
fputc(c, stream_target);
}
fclose(stream);
fclose(stream_target);
return 0;
}
=== test.txt content ===
test.txt - content
Test 1234
testcopy.txt content after copy
Test 1234
==== fputc output example ====
output: ./fputc
copy file