+ 1

Returns an array of string consisting of the characters in s split into tokens based on the delimeter c, followed by a

Suppose s is "I am ready for a nice vacation" and c is ' ', then I want return the arraylist {"I", "am", "ready", "for", "a", "nice", "vacation", NULL} I did the code below but it can not print out what I expect so is there someone who can help me to look at my code and fix it? Thanks https://code.sololearn.com/cb21G3FklJtV/#c

24th Oct 2018, 1:47 AM
Tuyen Pham
Tuyen Pham - avatar
5 odpowiedzi
0
The problem is at line 13. You split by ',' character instead of space. With space all works fine. There is also issue after line 50. You don't reset i counter and allocate more and more memory at each iteration. It is also good to check all +1. I think some of them are not required or doubled.
24th Oct 2018, 2:52 AM
Sergey Ushakov
Sergey Ushakov - avatar
0
are you willing to correct it?
24th Oct 2018, 3:33 AM
Tuyen Pham
Tuyen Pham - avatar
0
Just use t-p instead of i.
24th Oct 2018, 6:28 AM
Sergey Ushakov
Sergey Ushakov - avatar
0
i can not fix it? it still do not store into an array. Could you help me?
25th Oct 2018, 11:57 PM
Tuyen Pham
Tuyen Pham - avatar
0
Tuyen Pham just fix line #13 by str_chop_all(s, ' ');
26th Oct 2018, 9:36 AM
Sergey Ushakov
Sergey Ushakov - avatar