Advertisement
Tkap1

Untitled

Nov 23rd, 2022
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. struct s_split_word
  2. {
  3.     b8 has_new_line;
  4.     char word[128];
  5. };
  6.  
  7. func s_sarray<s_split_word, 128> split_str(char* text)
  8. {
  9.     s_sarray<s_split_word, 128> result;
  10.  
  11.     char* start = text;
  12.     int char_i = 0;
  13.     while(true)
  14.     {
  15.         char c = text[char_i];
  16.         if(c == ' ' || c == '\n' || c == 0)
  17.         {
  18.             s_split_word split_word = zero;
  19.             if(c == '\n')
  20.             {
  21.                 split_word.has_new_line = true;
  22.             }
  23.             char* end = &text[char_i];
  24.             memcpy(split_word.word, start, (u32)(end - start));
  25.             arr_add(&result, split_word);
  26.             start = &text[char_i + 1];
  27.         }
  28.         if(c == 0) { break; }
  29.         char_i += 1;
  30.     }
  31.  
  32.     return result;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement