Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- void f_space(char* str, int x)
- {
- int i, j;
- for (i = 0; i < x; i++)
- {
- if (str[0] == ' ')
- for (j = i; j < x; j++)
- str[j] = str[j + 1];
- else
- {
- if (str[i] == ' ' && str[i + 1] == ' ')
- {
- for (j = i; j < x; j++)
- str[j] = str[j + 1];
- i--;
- }
- }
- }
- if (str[strlen(str)-1] == ' ')
- str[strlen(str) - 1] = '\0';
- }
- void main()
- {
- char* ptrmin, * ptrmax, * ptrnow;
- int countletters = 0;
- int minletters = 100;
- int maxletters = -100;
- int i = 0;
- char* string = new char[100];
- gets_s(string, 100);
- puts("inputed string");
- puts(string);
- ptrmin = string;
- ptrmax = string;
- ptrnow = string;
- f_space(string, strlen(string) + 1);
- puts(string);
- for (*(string + i); i < strlen(string) + 1; i++)
- {
- if (*(string + i) != ' ' && *(string + i) != '\0')
- countletters++;
- else
- {
- if (countletters > maxletters)
- {
- ptrmax = ptrnow;
- maxletters = countletters;
- }
- if (countletters < minletters)
- {
- ptrmin = ptrnow;
- minletters = countletters;
- }
- countletters = 0;
- ptrnow = string + i + 1;
- }
- }
- printf_s("Minimal length word %p\n", ptrmin);
- i = 0;
- while (*(ptrmin + i) != ' ' && *(ptrmin + i) != '\0')
- {
- printf_s("%c", *(ptrmin + i));
- i++;
- }
- i = 0;
- printf_s("\n");
- printf_s("Maximal length word %p\n", ptrmax);
- while (*(ptrmax + i) != ' ' && *(ptrmax + i) != '\0')
- {
- printf_s("%c", *(ptrmax + i));
- i++;
- }
- delete[]string;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement