Programmation Avancée en C


ungetc.c

00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 
00004 #define FILEIN  "entree.txt"
00005 
00006 int main() 
00007 {
00008     FILE * fd;
00009     int c;
00010 
00011     if ( (fd = fopen(FILEIN, "r")) == NULL ) {
00012         perror("[Erreur] fopen");
00013         return 1; 
00014     }
00015     while ( (c = getc(fd)) != EOF ) {
00016         if (c == 0) ungetc('/', fd);
00017         putchar(c);
00018     }
00019     fclose(fd);
00020 
00021     return 0;
00022 }