Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream.h>
- #include <stdio.h>
- bool isLetter(char a)
- {
- if (a != ' ' && a != '.' && a != ',' && a != '!' &&
- a != '?' && a != '(' && a != ')' && a != ':' && a != ';') return true;
- return false;
- }
- int main ()
- {
- char fileName[80];
- printf("Имя файла: ");
- scanf("%s", fileName);
- ifstream fin(fileName, ios::in | ios::nocreate);
- if (!fin) { printf("Ошибка открытия файла.\n"); return 1; }
- fin.seekg(0, ios::end);
- long len = fin.tellg();
- char *buf = new char [len + 1];
- fin.seekg(0, ios::beg);
- fin.read(buf, len);
- buf[len] = '\0';
- long n = 0, i = 0, j = 0;
- printf("\nСодержимое файла %s :\n", fileName);
- while(buf[i])
- {
- printf("%c", buf[i]);
- if (isLetter(buf[i++])) { n++; continue; }
- if (n <= 4 && isLetter(buf[i-1])) j++;
- n = 0;
- i++;
- }
- fin.close();
- printf("\nКоличество слов из <= 4 букв: %d\n", j);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement