Almo
Masterblazer
void QMag::RemoveWord(u8 wordnum, bool answerquote)
{
char worktext[QMAG_MAX_QUOTE_LENGTH];
char* charpoint;
char* charpoint2;
int wordcount = 0;
int wordlen = 0;
int extrachar = 1;
if(answerquote)
{
strcpy(worktext, m_answerText);
}
else
{
strcpy(worktext, m_poolText);
}
charpoint = worktext;
while(*charpoint != '\0' && wordcount < wordnum) // find first char of word to remove
{
while(*charpoint != ' ' && *charpoint != '\0')
{
charpoint++;
}
wordcount++;
if(*charpoint == ' ')
{
charpoint++;
}
else
{
return;
}
}
charpoint2 = charpoint;
while(*charpoint2 != ' ' && *charpoint2 != '\0') // find length of word to be removed
{
wordlen++;
charpoint2++;
}
if(*charpoint2 == '\0') // check if removing last word; extrachar = 1 means there's a trailing space to keep
{
extrachar = 0;
}
while(*(charpoint + wordlen + extrachar) != '\0')
{
*charpoint = *(charpoint + wordlen + extrachar);
charpoint++;
}
if(extrachar == 0) // remove trailing space if at end of string
{
charpoint--;
}
*charpoint = '\0';
if(answerquote)
{
strcpy(m_answerText, worktext);
}
else
{
strcpy(m_poolText, worktext);
}
}
Subtle bug in here is causing it to fail when removing the only word from a one-word string. This is driving me crazy. Don't worry about trying to help, I'm just venting. I suspect string manipulation in C is horrible because Dennis Kenighan who helped design C is the K in AWK, which works fine once you know how to use it. Why put good string stuff in C when any C programmer can just use AWK?

{
char worktext[QMAG_MAX_QUOTE_LENGTH];
char* charpoint;
char* charpoint2;
int wordcount = 0;
int wordlen = 0;
int extrachar = 1;
if(answerquote)
{
strcpy(worktext, m_answerText);
}
else
{
strcpy(worktext, m_poolText);
}
charpoint = worktext;
while(*charpoint != '\0' && wordcount < wordnum) // find first char of word to remove
{
while(*charpoint != ' ' && *charpoint != '\0')
{
charpoint++;
}
wordcount++;
if(*charpoint == ' ')
{
charpoint++;
}
else
{
return;
}
}
charpoint2 = charpoint;
while(*charpoint2 != ' ' && *charpoint2 != '\0') // find length of word to be removed
{
wordlen++;
charpoint2++;
}
if(*charpoint2 == '\0') // check if removing last word; extrachar = 1 means there's a trailing space to keep
{
extrachar = 0;
}
while(*(charpoint + wordlen + extrachar) != '\0')
{
*charpoint = *(charpoint + wordlen + extrachar);
charpoint++;
}
if(extrachar == 0) // remove trailing space if at end of string
{
charpoint--;
}
*charpoint = '\0';
if(answerquote)
{
strcpy(m_answerText, worktext);
}
else
{
strcpy(m_poolText, worktext);
}
}
Subtle bug in here is causing it to fail when removing the only word from a one-word string. This is driving me crazy. Don't worry about trying to help, I'm just venting. I suspect string manipulation in C is horrible because Dennis Kenighan who helped design C is the K in AWK, which works fine once you know how to use it. Why put good string stuff in C when any C programmer can just use AWK?
Last edited:
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. 