Fich: lectura caracter a caracter. fgetc

17 lect caract a caract.html
/* Manejo de ficheros: Lectura carácter a carácter */

/*  */
 
# include <stdio.h>
int main( )
{
   FILE *fp ;
   char c ;
   printf( "Opening the file test.c in read mode\n" ) ;
   fp = fopen ( "test.txt", "r" ) ; // abrir fichero
   if ( fp == NULL )
   {
     printf ( "Could not open file test.c" ) ;
     return 1;
   }
   printf( "Reading the file test.c\n" ) ;
   printf("%c eof", EOF);
   while (!feof(fp)) //sustituir por --> while (1) descomentando 22,23
   {
     c = fgetc ( fp ) ; // Leyendo el fichero
     //if ( c == EOF )   // condicion EOF+break si while(1)
     //break ;
     printf ( "%c ", c ) ;
   }
   printf("Closing the file test.c") ;
   fclose ( fp ) ; // Cierre de fichero
   return 0;
}

 
 


No hay comentarios:

Publicar un comentario