Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3.  
  4. int main() {
  5. const char* inputFile = "../Test1.txt";
  6. FILE *in;
  7. in = fopen(inputFile, "r");
  8.  
  9. if (in == NULL) {
  10. printf("Файл не существует!!!");
  11. return 1;
  12. }
  13.  
  14. char max[80]; // Максимальное слово
  15. char min[80]; // Минимальное слово
  16. char temp[80]; // Переменная для записи
  17. int maxLen = 0; // Длина максимального слова
  18. int minLen = 80; // Длина минимального слова
  19. int wordsCount = 0; // Количество слов
  20. int i = 0; // Индекс для temp
  21. int s; // Переменная для считывания
  22.  
  23. s = fgetc(in);
  24. if (s == EOF) {
  25. printf("Файл пуст!!!");
  26. return 2;
  27. }
  28. while (s != EOF) {
  29. printf("%c", s);
  30. if (!isspace(s)) { //(s >= 'a' && s <= 'z') || (s >= 'A' && s <= 'Z')) {
  31. if (i == 0) {
  32. wordsCount++;
  33. }
  34. temp[i] = s;
  35. i++;
  36. } else {
  37. if (i != 0) {
  38. if (i > maxLen) {
  39. for (int j = 0; j < i; ++j) {
  40. max[j] = temp[j];
  41. }
  42. maxLen = i;
  43. }
  44. if (i < minLen) {
  45. for (int j = 0; j < i; ++j) {
  46. min[j] = temp[j];
  47. }
  48. minLen = i;
  49. }
  50. i = 0;
  51. }
  52. }
  53. s = fgetc(in);
  54. }
  55. if (wordsCount == 0) {
  56. printf("В файле нет слов!!!");
  57. return 0;
  58. }
  59. printf("\n\nКоличество слов = %d", wordsCount);
  60. printf("\nМаксимальное слово = ");
  61. for (int i = 0; i < maxLen; ++i) {
  62. printf("%c", max[i]);
  63. }
  64. printf("\nДлина максимального слова = %d", maxLen);
  65. printf("\nМинимальное слово = ");
  66. for (int i = 0; i < minLen; ++i) {
  67. printf("%c", min[i]);
  68. }
  69. printf("\nДлина минимального слова = %d", minLen);
  70.  
  71. return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement