Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- void aff(FILE *f)
- {
- int c;
- rewind(f);
- printf("The File contains:\n_______________________________________________________\n");
- while(!feof(f))
- {
- c=fgetc(f);
- printf("%c",c);
- }
- printf("\n_______________________________________________________\n");
- }
- int compte_car (FILE *f)
- {
- rewind(f);
- int cpt =0;
- int c;
- while (! feof(f))
- {
- c=fgetc(f);
- if (c!=32 && c!=10 && c!=-1 )
- {
- cpt++;
- }
- }
- return cpt ;
- }
- /////////////////////////////////////////////
- int compte_mot (FILE *f)
- {
- rewind(f);
- int c ;
- int cpt =0;
- while (! feof(f))
- {
- c=fgetc(f);
- if (c ==' ' || c=='\n')
- cpt++;
- }
- return cpt+1;
- }
- /////////////////////////////
- int compte_lig (FILE *f )
- {
- rewind(f);
- int c ;
- int cpt =0;
- while (! feof(f))
- {
- c=fgetc(f);
- if (c=='\n')
- cpt++;
- }
- return cpt+1;
- }
- int main()
- {
- FILE *f;
- f= fopen("test.txt","r");
- if (f==NULL)
- {
- printf("File Non Existent...Please Create The File In The Same Directory As the .exe File...|\n\n\n");
- }
- else
- {
- aff(f);
- printf("Num Of Chars: %d\n_______________________\n",compte_car(f));
- printf("Num Of Words: %d\n_______________________\n",compte_mot(f));
- printf("Num Of Lines: %d\n_______________________\n",compte_lig(f));
- fclose(f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement