Advertisement
Archangelpl

Untitled

Jun 9th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include<string.h>
  4. #include<locale.h>
  5. #include <stdlib.h>
  6. FILE *fd;
  7.  
  8. int main()
  9. {
  10. setlocale(LC_ALL, "polish");
  11. system("chcp 1250");
  12.  
  13.  
  14.  
  15. char k, l, pom;
  16. int i = 0;
  17. if (!(fd = fopen("tekst1.txt", "r")))
  18. {
  19. printf("Błąd wczytwania tekstu 1\n");
  20. exit(5);
  21. }
  22.  
  23. printf("\nTekst \n"); // Wypisywanie tekstu 1
  24. while (fscanf(fd, "%c", &k) != EOF)
  25. {
  26. printf("%c", k);
  27. }
  28. printf("\n");
  29.  
  30. fclose(fd);
  31.  
  32.  
  33. fd = fopen("tekst1.txt", "r");
  34. while (fscanf(fd, "%c", &k) != EOF ) // Szukanie wyrazów
  35. {
  36. fscanf(fd, "%c", &l);
  37. if (l == EOF && k != ' ')
  38. {
  39. i++;
  40. break;
  41. }
  42.  
  43.  
  44. if (k != ' ' && l == ' ')
  45. {
  46. i++;
  47. }
  48. if (k == ' ' && l != ' ')
  49. {
  50. i++;
  51. }
  52. }
  53. printf("Ilość wyrazów w tekscie to %d \n", i);
  54.  
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement