C Tutorial/stdio.h/putc — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
м (1 версия: Импорт контента...)
 
(нет различий)

Текущая версия на 13:32, 25 мая 2010

putc

Item Value Header file stdio.h Declaration int putc(int ch, FILE *stream); Function writes a character to the output stream. Return returns the character written on success and EOF on error.

For binary mode, you can use ferror() to determine whether an error has occurred.


<source lang="cpp">#include <stdio.h>

 int main(void){

   FILE *fp;
   if((fp=fopen("test", "w"))==NULL) {
     printf("Cannot open file.\n");
     exit(1);
   } 

   char *str = "www.java2s.com";

   for(; *str; str++){
       putc(*str, fp);
   }
 }</source>