Little 10 Toes
Master Poster
Still remember the saying Pascal is a water pistol aimed at everyone while C/C++ is a .357 aimed at your head.
Actually, it's an additional 2-year-hold hung on the side of the 3-year-old. And you know that the maturity of a 3-year-old plus the maturity of a 2-year-old does not equal the maturity of a 5-year-old.
I would suggest that you move the logic that decides which destination string to put the result in out of the function and make it a generic function that just modifies the string it is passed in-place.
Something like this:
...
Why are you using C strings in a C++ program? Why not use the STL String support?
[...] it's fixed. But I don't know why since my change was to fix a different problem in InsertWord.
/* Remove the nth word from the string s. (n is 0-based.)
Each word contains a single space, as its last character,
except possibly for the string's last word, which might
not contain any spaces.
Example:
n: 0 1 2 3 45 6
s: "abc de f g hi jkl"
*/
void remove(char *s, int n) {
char *b, *e; // beginning and one-past-end of word to be removed
for (b = s; *b && n; ++b)
if (*b == ' ') --n;
for (e = b; *e && *e++ != ' ';);
// when removing last word, remove preceding space too, if any
if (!*e && s<b && b<e) --b;
strcpy(b, e);
}
I guess there's a reason MacOS was written in PASCAL up through System 7.![]()
I appreciate the thought, but it's fixed. But I don't know why since my change was to fix a different problem in InsertWord.Glad to know I'm not the only programmer who finds pointers annoying. I guess there's a reason MacOS was written in PASCAL up through System 7.
![]()