FILE - C stdio.h

C examples for stdio.h:FILE

Type

data type

From


<cstdio>
<stdio.h>

Description

Object type that identifies a stream.

Example

This example reads the content of a text file called main.cpp and sends it to the standard output stream.

Demo Code


#include <stdio.h>

int main()/*from  w w w  .j a  v  a 2  s  .c o  m*/
{
   FILE * pFile;
   char buffer [100];

   pFile = fopen ("main.cpp" , "r");
   if (pFile == NULL) {
      perror ("Error opening file");
      return -1;
   }

   while ( ! feof (pFile) ){
       if ( fgets (buffer , 100 , pFile) == NULL ) break;
       fputs (buffer , stdout);
   }
   fclose (pFile);

   return 0;
}

Related Tutorials