Advertisement
Zennoma

Untitled

Feb 20th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. void f_space(char* str, int x)
  5. {
  6. int i, j;
  7. for (i = 0; i < x; i++)
  8. {
  9. if (str[0] == ' ')
  10. for (j = i; j < x; j++)
  11. str[j] = str[j + 1];
  12. else
  13. {
  14. if (str[i] == ' ' && str[i + 1] == ' ')
  15. {
  16. for (j = i; j < x; j++)
  17. str[j] = str[j + 1];
  18. i--;
  19. }
  20.  
  21. }
  22. }
  23. if (str[strlen(str)-1] == ' ')
  24. str[strlen(str) - 1] = '\0';
  25. }
  26.  
  27. void main()
  28. {
  29. char* ptrmin, * ptrmax, * ptrnow;
  30. int countletters = 0;
  31. int minletters = 100;
  32. int maxletters = -100;
  33. int i = 0;
  34. char* string = new char[100];
  35. gets_s(string, 100);
  36. puts("inputed string");
  37. puts(string);
  38. ptrmin = string;
  39. ptrmax = string;
  40. ptrnow = string;
  41. f_space(string, strlen(string) + 1);
  42. puts(string);
  43. for (*(string + i); i < strlen(string) + 1; i++)
  44. {
  45.  
  46. if (*(string + i) != ' ' && *(string + i) != '\0')
  47. countletters++;
  48. else
  49. {
  50. if (countletters > maxletters)
  51. {
  52. ptrmax = ptrnow;
  53. maxletters = countletters;
  54. }
  55. if (countletters < minletters)
  56. {
  57. ptrmin = ptrnow;
  58. minletters = countletters;
  59. }
  60. countletters = 0;
  61. ptrnow = string + i + 1;
  62. }
  63. }
  64. printf_s("Minimal length word %p\n", ptrmin);
  65. i = 0;
  66. while (*(ptrmin + i) != ' ' && *(ptrmin + i) != '\0')
  67. {
  68. printf_s("%c", *(ptrmin + i));
  69. i++;
  70. }
  71. i = 0;
  72. printf_s("\n");
  73. printf_s("Maximal length word %p\n", ptrmax);
  74. while (*(ptrmax + i) != ' ' && *(ptrmax + i) != '\0')
  75. {
  76. printf_s("%c", *(ptrmax + i));
  77. i++;
  78. }
  79. delete[]string;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement