Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. FILE *fp;
  2. int i = 0;
  3. int j = 0;
  4. char buffer[1024];
  5. int NumeroParole = 0;
  6. int NumeroCaratteri = 0;
  7.  
  8. fp = fopen("C:\\Users\\Luigi\\eclipse-workspace\\studente_file\\studenti.txt", "r");
  9. if(fp != NULL) {
  10. while(!feof(fp)) {
  11. while(fgets(buffer, sizeof(buffer), fp)) {
  12. j = 0;
  13. while(j < (strlen(buffer))) {
  14. if(buffer[j] == ' ' || buffer[j] == '\n') NumeroParole = NumeroParole + 1;
  15. j = j + 1;
  16. }
  17. printf("%s", buffer);
  18. NumeroCaratteri = NumeroCaratteri + strlen(buffer) - 1;
  19. }
  20. i = i + 1;
  21. }
  22. } else {
  23. printf("Il file speficifacto non esiste!");
  24. }
  25.  
  26. printf("\nCaratteri contati: %d\n", NumeroCaratteri);
  27. printf("Parole contate: %d\n", NumeroParole);
  28. fclose(fp);
  29.  
  30. system("PAUSE");
  31. return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement