Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. // Поиск самого длинного слова в строке.
  8. char* Del_small_W (char * str)
  9. {
  10.     int len = 0; // длина строки
  11.     int i = 0;
  12.     int MAX = 0;
  13.     int startPos, finPos;
  14.     char *Lword; // самое длинное слово
  15.     while (str[i] != NULL)
  16.     {
  17.         if ((str[i] != 32)&&(str[i + 1] != NULL))
  18.             len++;
  19.         else
  20.         {
  21.             if (len > MAX)
  22.             {
  23.                 MAX = len;
  24.                 Lword = new char[MAX];
  25.                 startPos = i - MAX;
  26.                 int j = 0;
  27.                 for (startPos; startPos < i; startPos++)
  28.                 {
  29.                     Lword[j] = str[startPos];
  30.                     j++;
  31.                 }
  32.                 Lword [j]=  '\0';
  33.             }
  34.             len = 0;
  35.         }
  36.         i++;
  37.     }
  38.     return Lword;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement