Advertisement
Archangelpl

ilosc slow w tekscie

Jun 9th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 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, *c;
  16. int j = 0, o = 0, p = 0;
  17. if (!(fd = fopen("tekst.txt", "r")))
  18. {
  19. printf("Błąd wczytwania tekstu 1\n");
  20. exit(5);
  21. }
  22.  
  23.  
  24. while (fscanf(fd, "%c", &k) !=EOF)
  25. {
  26. j++;
  27.  
  28. }
  29. for (int i = 0; i <= j;i++)
  30. {
  31.  
  32. c= malloc(j * sizeof(char));
  33. }
  34. fclose(fd);
  35.  
  36. fd = fopen("tekst1.txt", "r");
  37. while (fscanf(fd, "%c", &k) != EOF)
  38. {
  39. c[o] = k;
  40. o++;
  41.  
  42. }
  43. for (int i = 0; i < j; i++)
  44. {
  45. printf("%c", c[i]);
  46. }
  47. printf("\n");
  48. for (int i = 1; i < j; i++)
  49. {
  50. if (c[i - 1] != ' ' && c[i] == ' ')
  51. {
  52. p++;
  53. }
  54. }
  55. if(c[j-1]!=' ')
  56. {
  57. p++;
  58. }
  59. printf("Ilość wyrazów w tekscie to %d \n", p);
  60.  
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement