Cod sursa(job #2429920)

Utilizator andrei885Andrei Paul Vintila andrei885 Data 11 iunie 2019 20:46:55
Problema Text Scor 100
Compilator c-64 Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void main() {
  FILE *fp = fopen("text.in", "r");

  int total_length = 0;
  int no_of_words = 0;
  int ok = 0;
  char c;
  while ((c = fgetc(fp)) != EOF)
    if (c >= 'A' && c <= 'Z' || c >= 'a' && c <= 'z') {
      total_length++;
      if (!ok) {
        no_of_words++;
        ok = 1;
      }
    }
    else
      ok = 0;

  fclose(fp);
  int res = total_length / no_of_words;

  fp = fopen("text.out", "w");
  fprintf(fp, "%d", res);
  fclose(fp);
}