ArfIsAToe

files for C and baha

Jun 11th, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void aff(FILE *f)
  4. {
  5.     int c;
  6.     rewind(f);
  7.     printf("The File contains:\n_______________________________________________________\n");
  8.     while(!feof(f))
  9.     {
  10.         c=fgetc(f);
  11.         printf("%c",c);
  12.     }
  13.     printf("\n_______________________________________________________\n");
  14. }
  15.  
  16. int compte_car (FILE *f)
  17. {
  18.     rewind(f);
  19.     int cpt =0;
  20.     int c;
  21.     while (! feof(f))
  22.     {
  23.         c=fgetc(f);
  24.         if (c!=32 && c!=10 && c!=-1 )
  25.         {
  26.             cpt++;
  27.         }
  28.     }
  29.     return cpt ;
  30. }
  31. /////////////////////////////////////////////
  32. int compte_mot (FILE  *f)
  33. {
  34.     rewind(f);
  35.     int c ;
  36.     int cpt =0;
  37.     while (! feof(f))
  38.     {
  39.          c=fgetc(f);
  40.          if (c ==' ' || c=='\n')
  41.             cpt++;
  42.     }
  43.     return cpt+1;
  44. }
  45. /////////////////////////////
  46. int compte_lig (FILE   *f )
  47. {
  48.     rewind(f);
  49.     int c ;
  50.     int cpt =0;
  51.     while (! feof(f))
  52.     {
  53.         c=fgetc(f);
  54.         if (c=='\n')
  55.             cpt++;
  56.     }
  57.     return cpt+1;
  58. }
  59. int main()
  60. {
  61.     FILE *f;
  62.     f= fopen("test.txt","r");
  63.     if (f==NULL)
  64.     {
  65.         printf("File Non Existent...Please Create The File In The Same Directory As the .exe File...|\n\n\n");
  66.     }
  67.     else
  68.     {
  69.         aff(f);
  70.         printf("Num Of Chars: %d\n_______________________\n",compte_car(f));
  71.         printf("Num Of Words: %d\n_______________________\n",compte_mot(f));
  72.         printf("Num Of Lines: %d\n_______________________\n",compte_lig(f));
  73.         fclose(f);
  74.     }
  75. }
  76.  
Add Comment
Please, Sign In to add comment