d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With Syllables > C++
Add Reply New Topic New Poll
Member
Posts: 467
Joined: Nov 18 2013
Gold: 0.00
Sep 20 2015 06:00pm
Does anyone know how to split a string by spaces to make it an array of words? I want to take those words and add heighens to show where the syllables should be.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 20 2015 06:05pm
first part is pretty easy: http://stackoverflow.com/questions/236129/split-a-string-in-c

it's the second part you'll need to elaborate on. how are you determining where a syllable is?
Member
Posts: 467
Joined: Nov 18 2013
Gold: 0.00
Sep 20 2015 06:08pm
Quote (carteblanche @ Sep 20 2015 07:05pm)
first part is pretty easy: http://stackoverflow.com/questions/236129/split-a-string-in-c

it's the second part you'll need to elaborate on. how are you determining where a syllable is?



1. If the pattern vowel-consonant-consonant-vowel is found, hyphenate between the two consonants. Use ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ as vowels, and all other characters as consonants.
2. If the pattern vowel-consonant-vowel is found, hyphenate before the consonant unless the second vowel is an ‘e’ and occurs at the end of the word.
3. The following character sequences are never divided by hyphens: “qu”, “tr”, “br”, “str”, “st”, “sl”, “bl”, “cr”, “ph”, “ch”. For the purposes of rules 1 and 2, each of these are single consonants.
4. Upper and lower-case distinctions are ignored for the purpose of applying the above rules. However, the case in the input must be preserved in the output.


these are the rules for where to insert hyphens in the string.
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 20 2015 06:13pm
Quote (Arstar04 @ Sep 20 2015 08:08pm)
1. If the pattern vowel-consonant-consonant-vowel is found, hyphenate between the two consonants. Use ‘a’, ‘e’, ‘i’, ‘o’, ‘u’, and ‘y’ as vowels, and all other characters as consonants.
2. If the pattern vowel-consonant-vowel is found, hyphenate before the consonant unless the second vowel is an ‘e’ and occurs at the end of the word.
3. The following character sequences are never divided by hyphens: “qu”, “tr”, “br”, “str”, “st”, “sl”, “bl”, “cr”, “ph”, “ch”. For the purposes of rules 1 and 2, each of these are single consonants.
4. Upper and lower-case distinctions are ignored for the purpose of applying the above rules. However, the case in the input must be preserved in the output.


these are the rules for where to insert hyphens in the string.


that sounds incredibly dumb. for example, "other" would become ot-her? anyway. what part of that do you need help with? just iterate over each character to determine if it's vowel / consonant, then use your rules to add hyphen.

This post was edited by carteblanche on Sep 20 2015 06:16pm
Member
Posts: 467
Joined: Nov 18 2013
Gold: 0.00
Sep 20 2015 06:15pm
Quote (carteblanche @ Sep 20 2015 07:13pm)
that sounds incredibly dumb. for example, "other" would become ot-her? anyway. what part of that do you need help with? just iterate over each character to determine if it's vowel / consonant, then use your rules to add hyphen


i literally just started c++ so the syntax is hard for me. and it would be "o-ther" because the hyphen is before the consonant. But once you split the string, how do i access the single words/ array of words?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 20 2015 06:16pm
Quote (Arstar04 @ Sep 20 2015 08:15pm)
i literally just started c++ so the syntax is hard for me. and it would be "o-ther" because the hyphen is before the consonant. But once you split the string, how do i access the single words/ array of words?


if you're new to coding, i suggest going through an example while writing down your logic first, then converting it to pseudocode, then c++ at the end. dont get too hung up over syntax yet. post here with your pseduocode.

This post was edited by carteblanche on Sep 20 2015 06:17pm
Member
Posts: 467
Joined: Nov 18 2013
Gold: 0.00
Sep 20 2015 06:24pm
Quote (carteblanche @ Sep 20 2015 07:16pm)
if you're new to coding, i suggest going through an example while writing down your logic first, then converting it to pseudocode, then c++ at the end. dont get too hung up over syntax yet. post here with your pseduocode.



im not new to coding but just new to c++. the method below is what I'm using for this. i want to take the input and convert it into a string. split the string by empty spaces just to get the word. go through the word looking for vowels and adding hyphens according to rules but I'm not sure how to go about splitting it and accessing those split words and then converting back to char*

char* getWords(const char* input)
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 20 2015 07:09pm
Quote (Arstar04 @ Sep 20 2015 08:24pm)
im not new to coding but just new to c++. the method below is what I'm using for this. i want to take the input and convert it into a string. split the string by empty spaces just to get the word. go through the word looking for vowels and adding hyphens according to rules but I'm not sure how to go about splitting it and accessing those split words and then converting back to char*

char* getWords(const char* input)


i didn't mean that this is your first time coding, but you still seem new to it.

http://www.cplusplus.com/reference/string/string/substr/

See also
string::replace Replace portion of string (public member function )
string::data Get string data (public member function )
string::find Find content in string (public member function )
string::assign Assign content to string (public member function )
string::string Construct string object (public member function )
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll