Advertisement
Guest User

Untitled

a guest
Feb 27th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. int split(char* s, char*** words){
  2. int count = 0, flag = 0;
  3. for (int i=0; s[i] != 0; i++){
  4. if (s[i] != 32 && flag == 0){
  5. count += 1;
  6. flag = 1;
  7. continue;
  8. }
  9. if (s[i] == 32 && flag == 1){
  10. flag = 0;
  11. }
  12. }
  13. *words = (char**)malloc(count*sizeof(char*));
  14. for (int i=0; i<count; i++)
  15. (*words)[i] = (char*)calloc(50, sizeof(char));
  16. count = 0;
  17. flag = 0;
  18. int k = 0;
  19. for (int i=0; s[i] != 0; i++){
  20. if (s[i] != 32 && flag == 0){
  21. count += 1;
  22. flag = 1;
  23. k = 0;
  24. (*words)[count-1][k] = s[i];
  25. continue;
  26. }
  27. if (s[i] != 32 && flag == 1){
  28. k+=1;
  29. (*words)[count-1][k] = s[i];
  30. continue;
  31. }
  32. if (s[i] == 32 && flag == 1) flag = 0;
  33. }
  34. return count;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement