Implement char * ithword(char * str, int i)
that will return the i
th word in str. The words are alphanumeric and separated by non-alphanumeric characters. The function will allocate memory for the word returned, and return a pointer to it.
My approach is :
Start traversing the string and count the numbers of spaces and non-alphanumeric characters and when the count reaches i-1
, start printing till you get another space or non-alphanumeric characters.
Is it correct?