Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <fstream.h>
  2. #include <stdio.h>
  3.  
  4. bool isLetter(char a)
  5. {
  6.     if (a != ' ' && a != '.' && a != ',' && a != '!' &&
  7.             a != '?' && a != '(' && a != ')' && a != ':' && a != ';') return true;
  8.    
  9.     return false;
  10. }
  11. int main ()
  12. {
  13.     char fileName[80];
  14.     printf("Имя файла: ");
  15.     scanf("%s", fileName);
  16.     ifstream fin(fileName, ios::in | ios::nocreate);
  17.     if (!fin) { printf("Ошибка открытия файла.\n"); return 1; }
  18.  
  19.     fin.seekg(0, ios::end);
  20.     long len = fin.tellg();
  21.     char *buf = new char [len + 1];
  22.     fin.seekg(0, ios::beg);
  23.     fin.read(buf, len);
  24.     buf[len] = '\0';
  25.     long n = 0, i = 0, j = 0;
  26.     printf("\nСодержимое файла %s :\n", fileName);
  27.     while(buf[i])
  28.     {
  29.         printf("%c", buf[i]);
  30.         if (isLetter(buf[i++])) { n++; continue; }
  31.         if (n <= 4 && isLetter(buf[i-1])) j++;
  32.         n = 0;
  33.         i++;
  34.     }
  35.     fin.close();
  36.     printf("\nКоличество слов из <= 4 букв: %d\n", j);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement