User Tools

Site Tools


c:stdio.h:fputc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:stdio.h:fputc [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== fputc =====
 +
 +<code c>
 +    int fputc(int ch, FILE *stream); 
 +</code>
 +Writes ch, to stream stream. Returns ch, or EOF on error.
 +
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * fputc example code
 + * http://code-reference.com/c/stdio.h/fputc 
 + */
 +
 +
 +#include <stdio.h> /* including standard library */
 +//#include <windows.h> /* 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;
 +}
 +
 +</code>
 +
 +=== test.txt content ===
 +test.txt - content
 +<code c>
 +Test 1234
 +</code>
 +
 +testcopy.txt content after copy
 +<code c>
 +Test 1234
 +</code>
 +
 +==== fputc output example ====
 +    output: ./fputc
 +    copy file
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fputc.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz