Hi,
"Hilary Cotter" <hi*****@att.net> wrote in message
news:3b**************************@posting.google.c om...
| // string has embedded '+', this code will not work.
| VOID PatchQuery(char *szQuery, char **ppszPatchedQuery)
As Ema pointed out, the code you posed does not compile...
But from the function's signature and code snippet, I see
two things that can go wrong:
- The type of the char **ppszPatchedQuery suggests that
the PatchQuery function will use it to return a pointer
to a newly allocated memory buffer. Is this intended ?
This is not what the function currently does...
Suggestion: consider letting the caller allocate
the destination buffer...
- If your function is called by passing a string literal
as the first parameter, the function may trigger an
access violation, as it modifies the contents
of szQuery.
PatchQuery("a+b",&pbuf); // will crash
Suggestion: do not modify the source string. Only
modify the copy you create.
| I get an access violation when I try to replace the + with a space.
| Can anyone tell me how to do this?
I'm afraid this could be homework... but here's a way
to implement equivalent functionality:
void patch_query(char const* src, char* dst)
{
char c;
do {
c = *src++;
*dst++ = (c=='+') ? ' ' : c;
} while(c);
}
Cheers,
--
http://www.post1.com/~ivec