User Tools

Site Tools


c:stdio.h:putc

Differences

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

Link to this comparison view

c:stdio.h:putc [2013/01/22 22:02] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +
 +===== putc =====
 +<code c>
 +    int putc(int char, FILE *stream); 
 +</code>
 +
 +put char into a stream.
 +
 +===== C Sourcecode Example =====
 +<code c>
 +/* 
 + * 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;
 +}
 +
 + 
 +</code>
 +
 +=== content of test.txt ===
 +<code c>
 +Test example file for code-reference.com putc source code
 +</code>
 +
 +==== output ====
 +    ./putc 
 +    Test example file for code-reference.com putc source code
 +
 +output of test_copy.txt
 +<code c>
 +Test example file for code-reference.com putc source code
 +</code>
 +
 +**see also**
 +[[c:stdio.h:getc|]]
 +    
  
advertising
c/stdio.h/putc.txt · Last modified: 2013/01/22 22:02 (external edit)

Impressum Datenschutz