If you have a string of characters of type char* and you need to break it up into words, you can:
1. Create an array of pointers of the type char*. Create a word counter. 2. Save the current value of string length. Assign the first pointer to the address of the beginning of the string. Increase counter value. 3. In a cycle from zero to the length of the string replace all the non-letters with the symbol “\0” (end of line character). (You can check if the symbol is a letter or not with the function isalpha). Save to a pointer array the address of the symbol going after non-letter. Increase the count of the number of words. 4. You must then go through the formed array and remove empty words from there.
Note: the word count is useful for indexing the pointer in an array of pointers. For example words[n]=&str[i]; Since words in C have the ending “\0”, you will have a set of strings that will be kept in the same place as before, but it will be possible to work with them as with the separate strings.
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment