Permalink
Browse files

finalize word generator code

  • Loading branch information...
1 parent 83fcff8 commit 9ddbc5d78b69ed49958672051b988ddb34d0fe6e @sweemeng committed Apr 23, 2011
Showing with 12 additions and 9 deletions.
  1. +10 −7 libraries/storyboard/WordGenerator.cpp
  2. +1 −1 libraries/storyboard/WordGenerator.h
  3. +1 −1 storybox/storybox.pde
@@ -64,8 +64,7 @@ int WordGenerator::get_delimiter(int pos){
return p;
}
-void WordGenerator::word_select(char *word_selected){
- free(word_selected);
+char *WordGenerator::word_select(){
int word_start = TrueRandom.random(this->segment_begin,this->segment_end);
word_start = this->get_delimiter(word_start);
if(word_start == this->segment_end){
@@ -83,14 +82,18 @@ void WordGenerator::word_select(char *word_selected){
//Serial.println(word_size);
char *s_word;
s_word = (char *)malloc(word_size * sizeof(char));
+ int count = 0;
+
for(int i = word_start;i < word_end;i++){
- *s_word = storage.read(i);
- //Serial.println(*s_word);
- s_word++;
+ s_word[count] = storage.read(i);
+ //s_word++;
+ count++;
+ if(count == word_size){
+ break;
+ }
//delay(500);
}
- word_selected = s_word;
- Serial.println(word_selected);
+ return s_word;
}
int WordGenerator::get_segment_begin(){
@@ -12,7 +12,7 @@ class WordGenerator{
int byte_to_int(byte *);
void get_segment(int);
int get_delimiter(int);
- void word_select(char *);
+ char *word_select();
int get_segment_begin();
int get_segment_end();
void put_storage(int,int);
@@ -34,7 +34,7 @@ void setup() {
void loop(){
bouncer.update();
- int value = bouncer.read()
+ int value = bouncer.read();
lcd.clear();
char words;
if(value == HIGH){

0 comments on commit 9ddbc5d

Please sign in to comment.