SHARE
TWEET

Untitled

a guest Jan 19th, 2020 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. long getWords(char str[])
  2. {
  3.     long count = 0;
  4.     long strLength = strLen(str);
  5.  
  6.     int currentPosition = 0;
  7.  
  8.     char words[100][100]{ 0 };
  9.  
  10.     if (strLength == 0)
  11.         return -1;
  12.  
  13.     for (int i = 0; i <= strLen(str); i++)
  14.     {
  15.         if (str[i] != ' ' && str[i] != '\t' && str[i] != '\0')
  16.         {
  17.             words[count][currentPosition] = str[i];
  18.             currentPosition++;
  19.         }
  20.         else if((str[i] == ' ' || str[i] == '\t' || str[i] == '\0') && str[i - 1] != '\t' && str[i - 1] != ' ')
  21.         {
  22.             count++;
  23.             currentPosition = 0;
  24.         }
  25.     }
  26.  
  27.     for (int i = 0; i < count; i++)
  28.     {
  29.         std::cout << words[i] << "-";
  30.     }
  31.  
  32.  
  33.     return count;
  34.    
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top