Advertisement
AntonioVillanueva

Read File in C

Dec 8th, 2022
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | Software | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5.  
  6. char FileName[]="SmartLPR.ini";//Nom du fichier à ouvrir
  7. #define MAX_LENGTH 64 //longueur maximale d'une ligne
  8. int main (){
  9.    
  10.     char ligne[255];//Une ligne
  11.     char buffer[1024];//Buffer fichier
  12.  
  13.     FILE *f = fopen(FileName, "r");
  14.  
  15.     if (f==NULL)
  16.     {      
  17.         fprintf(stderr," Erreur d'ouverture de fichier  %s \n",FileName);
  18.         return -1;
  19.     }
  20.  
  21.     while (! feof (f)){//Décharge ligne par ligne le fichier f dans le buffer
  22.         fgets( ligne, MAX_LENGTH, f );
  23.         strcat (buffer,ligne);
  24.     }
  25.  
  26.     printf ("%s\n",buffer);
  27.  
  28.     fclose(f);//Close file
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement