Okay in attempting what's supposed to be a simple function...I have once again been thwarted at every turn.
(As usual I'm working in pure Win32 API C++)
I'm grabbing a block of text from an edit control, this is then passed to a function that puts it together with other bits of info that are used to build a SQL Query. The SQL Query is then fired against the db where it hopefully doesn't fail (Error checking abounds...).
Simple Right? ...Ha!
The problem is that if someone enters a possessive like "Joker's", the apostrophe which is a SQL control character causes the Query/function to fail. So I'm trying to replace every instance of ' with '' (Which is 2 apostrophes Not a double quote). Therein lying the rub...
I have spent the last 3 days trying the find a way to walk the string and insert a 2nd apostrophe anywhere there is a first. Everything that Google turns up referrers to the insert(...) function in namespace std; ... That's nice... except my use of the StringSafe routines (in the other 80 pages of code...) causes the compiler to spew errors for about a half an hour due to the inclusion of string.h (required by namespace std; ) .
I've seen this type of function before where the string to parsed through a series of pointers... but I never have quite understood it. ...Hence my inability to use it effectively.
So... Here's the block of poo I'm working with which will hopefully convey what I'm after:
void CleanString(char *szDirty) {
char *p;
p = szDirty;
if(p == 0) {
return;
}else{
while(*p) {
if(*p == '\'') {
MessageBox(0, p, "Found IT!", MB_OK);
*p += '\'';
MessageBox(0, p, "*pTmp++ = ?", MB_OK);
p = CharNext(p);
// pTmp += 1;
}else{
p = CharNext(p);
}
}
*p = 0;
MessageBox(0, p, "*pTmp = 0", MB_OK);
}
}
The MessageBoxes are only there for debugging purposes so I can tell what it's interpretation of what I just told it was.
Everything I try either drops the 2nd apostrophe or the s that comes after it. *Sigh*
What am I doing wrong?
Thank You,
Stoic Joker