User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:stdio.h:fgetc

fgetc

    int fgetc ( FILE * stream );

Returns next character from (input) stream stream, or EOF on end-of-file or error.

C Sourcecode Example

/* 
 * fgetc example code
 * http://code-reference.com/c/stdio.h/fgetc 
 */
 
 
#include <stdio.h> /* including standard library */
//#include <windows.h> /* uncomment this for Windows */
 
 
int main( void )
{
  FILE *stream;
  char c;
 
  if((stream=fopen("test.txt","r"))==NULL) {
    printf("Cannot open file.\n");
    return 1;
  }
 
  while((c = fgetc(stream) ) != EOF) {
    printf("%c", c);
  }
  fclose(stream);
  return 0;
}

test.txt

test.txt contents

Line 1
#Line2
Line 3
#Line 4 
Line 5

fgetc output

if test.txt exists

  output: ./fgetc 
  Line 1
  #Line2
  Line 3
  #Line 4 
  Line 5

if test.txt not exists

  output: ./fgetc 
  Cannot open file.

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/stdio.h/fgetc.txt · Last modified: 2014/12/04 13:27 by Daniel Gohlke

Impressum Datenschutz