C Tutorial/stdio.h/fgetc


Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /var/www/cppe.ru/www/includes/parser/Preprocessor_DOM.php on line 803

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/includes/exception/MWExceptionHandler.php on line 179

Deprecated: Constant E_STRICT is deprecated in /var/www/cppe.ru/www/vendor/mediawiki/at-ease/src/Functions.php on line 48
Материал из C\C++ эксперт
Версия от 10:32, 25 мая 2010; Admin (обсуждение | вклад) (1 версия: Импорт контента...)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

fgetc

Item Value Header

  1. include <stdio.h>

Declaration int fgetc(FILE *stream); Function gets the next character from the stream and increments the file position pointer. Return EOF: if the end of the file is reached.

  1. When working with binary files
  2. use feof() to check for the end of the file.
  3. use ferror() to check for file errors.


#include <stdio.h>
  #include <stdlib.h>
  int main(int argc, char *argv[])
  {
    FILE *fp;
    char ch;
    if((fp=fopen("test","r"))==NULL) {
      printf("Cannot open file.\n");
      exit(1);
    }
    while((ch=fgetc(fp)) != EOF) {
      printf("%c", ch);
    }
    fclose(fp);
    return 0;
  }