Advertisement
kacxsku

Untitled

Apr 4th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. //Liczba słów w wielu liniach tekstu (1) ­ tablice o dwóch indeksach
  2. #pragma warning (disable: 4996)
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #define MAX_LINE 256
  7. #define MAX_LINES 200
  8. FILE *fd = NULL;
  9. int ile_slow(char *);
  10. int main()
  11. {
  12.     char d[MAX_LINES][MAX_LINE];
  13.     int i, l;
  14.     if (!(fd = fopen("DANE.txt", "r")))
  15.     {
  16.         printf("Blad otwarcia zbioru\n");
  17.         exit(2);
  18.     }
  19.     i = 0;
  20.     l = 0;
  21.     while (i < MAX_LINES && fgets(d[i], MAX_LINE, fd) != (char*)NULL)
  22.     {
  23.         l += ile_slow(d[i]);
  24.         i++;
  25.     }
  26.     fclose(fd);
  27.     fd = NULL;
  28.     printf("%d\n", l);
  29.     system("pause");
  30. }
  31. /* TU funkcja ile_slow */
  32. int ile_slow(char *te)
  33. {
  34.     char p, b = ' ';
  35.     int l = 0;
  36.     while (p = b, b = *te++)
  37.         if (b != ' ' &&  p == ' ') l++;
  38.     return(l);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement