Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdbool.h>
  4. #include <mem.h>
  5.  
  6. char analyze(char *pattern);
  7.  
  8. int main( )
  9. {
  10. char pattern[256];
  11.  
  12. printf("Podaj tekst: ");
  13. fflush(stdin);
  14. scanf("%[^\n]255s", pattern);
  15.  
  16. analyze(pattern);
  17.  
  18. }
  19. char analyze(char *pattern)
  20. {
  21. int possition;
  22. int NumberOfLetters = 0;
  23. char *ArrayOfWords = NULL;
  24. bool CanIWrite = false;
  25.  
  26. for(possition = 0; possition < 256; possition++)
  27. {
  28. if(possition == 0)
  29. {
  30. if(pattern[possition] >= 48 && pattern[possition] <= 57)
  31. {
  32. CanIWrite = true;
  33. }
  34. }
  35.  
  36. if(pattern[possition] >= 48 && pattern[possition] <= 57 && pattern[possition - 1] == 32)
  37. {
  38. CanIWrite = true;
  39. }
  40.  
  41. if(pattern[possition] == 32)
  42. {
  43. CanIWrite = false;
  44. NumberOfLetters++;
  45. ArrayOfWords = (char*)realloc(ArrayOfWords,NumberOfLetters*sizeof(char));
  46. *(ArrayOfWords + NumberOfLetters - 1) = 32;
  47. }
  48.  
  49. if(CanIWrite == true)
  50. {
  51. NumberOfLetters++;
  52. ArrayOfWords = (char*)realloc(ArrayOfWords,NumberOfLetters*sizeof(char));
  53. *(ArrayOfWords + NumberOfLetters - 1) = pattern[possition];
  54. }
  55. }
  56.  
  57. for(possition = 0; possition < strlen(ArrayOfWords); possition++)
  58. {
  59. printf("%c", ArrayOfWords[possition]);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement