Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FILE *fp;
- int i = 0;
- int j = 0;
- char buffer[1024];
- int NumeroParole = 0;
- int NumeroCaratteri = 0;
- fp = fopen("C:\\Users\\Luigi\\eclipse-workspace\\studente_file\\studenti.txt", "r");
- if(fp != NULL) {
- while(!feof(fp)) {
- while(fgets(buffer, sizeof(buffer), fp)) {
- j = 0;
- while(j < (strlen(buffer))) {
- if(buffer[j] == ' ' || buffer[j] == '\n') NumeroParole = NumeroParole + 1;
- j = j + 1;
- }
- printf("%s", buffer);
- NumeroCaratteri = NumeroCaratteri + strlen(buffer) - 1;
- }
- i = i + 1;
- }
- } else {
- printf("Il file speficifacto non esiste!");
- }
- printf("\nCaratteri contati: %d\n", NumeroCaratteri);
- printf("Parole contate: %d\n", NumeroParole);
- fclose(fp);
- system("PAUSE");
- return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement