User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:putc

Table of Contents

putc

    int putc(int char, FILE *stream); 

put char into a stream.

C Sourcecode Example

/* 
 * putc example code
 * http://code-reference.com/c/stdio.h/putc 
 */
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
int main( void )
{
  int c;
  FILE *stream, *destination;
 
  stream = fopen("test.txt", "r");
  destination = fopen("test_copy.txt","w");
 
  if (stream == 0 || destination == 0) { 
     perror("cannot open stream");
     return 1;
   }
 
    c = getc(stream);
    while (c != EOF)
    {
      putc(c, stdout);
      putc(c, destination);
      c = getc(stream); 
    }
 
  fclose(stream);
  fclose(destination);
  return 0;
}
 
 

content of test.txt

Test example file for code-reference.com putc source code

output

  ./putc 
  Test example file for code-reference.com putc source code

output of test_copy.txt

Test example file for code-reference.com putc source code

see also getc

on the occasion of the current invasion of Russia in Ukraine

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

Impressum Datenschutz