compiles fine using gcc - segfaults here:
just a little program to pull out words from a longer string (words being strings of characters between whitespace).Code:while ( lower <= length ) { upper = s1.find( s2, lower ); // location of space word.assign( s1, lower, (upper - lower) ); // SEG HERE!!! array[counter] = word; // take value from word and assign to array counter++; // increase counter used to step thru array space lower = upper + 1; // for next iteration, start one char to the right of our last 'upper' bound }
s1 = "my dog has fleas but my cat don't"
s2 = " "
word = ""
length = s1.length()
initial value of lower is 0 -- both lower & upper are ints.
I guess I must be using assign wrong, but can't seem to figure out how.