User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:fputc

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 <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;
}

test.txt content

test.txt - content

Test 1234

testcopy.txt content after copy

Test 1234

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