Re: Directory is a "a file system object" ?
- From: "Ben Voigt" <bvoigt@xxxxxxxxxxxxx>
- Date: Fri, 13 Jan 2006 13:14:58 -0600
See comments below:
"vlg" <I.dare.you.to.hit.the.SPAM.button@xxxxxxxxx> wrote in message
news:eCizpyEGGHA.3856@xxxxxxxxxxxxxxxxxxxxxxx
> thanks.
>
> but now I have a strange problem constructing pFrom buffer
>
> the format is: Each file name must be terminated by a single NULL
> character. An additional NULL character must be appended to the end of the
> final name to indicate the end of pFrom
>
> my code works only if the "single NULL separator", is any other char then
> \0 !!!!!!!
>
> i have no ideea what is wrong ...
>
> i'll post some code, maybe someone can help ...
>
> text_to_add - text to be added
> text_to_add_len - strlen(text_to_add)
> szBuff - output string
>
> if (szBuff!=NULL) {
> iSize = iSize+text_to_add_len+1;
> szBuff = (TCHAR*)realloc(szBuff,iSize*sizeof(TCHAR));
> wsprintf(szBuff,TEXT("%s\0%s"),szBuff,text_to_add); // if I replace here
> \0
As far as wsprintf is concerned, your format string TEXT("%s\0%s") is the
same as "%s" because a string ends at the first NUL.
> with # , the szBuff is fine
> //strcat(szBuff,text_to_add);
> //strcat(szBuff,TEXT("\0"));
This is better, but when you append the next thing, it's not going to follow
the NUL, it's going to replace the NUL, because the string ends at the first
NUL.
ASCII-Z strings aren't counted, so they cannot contain embedded nulls.
try:
TCHAR* szBuffer = (TCHAR*)malloc(BIGSIZE);
TCHAR* pchEnd = szBuffer;
for( ... ) {
/* from wsprintf documentation:
If the function succeeds, the return value is the number of
characters stored in the output buffer, not counting the terminating null
character.
Add one for the terminating null character.
*/
pchEnd += 1 + wsprintf(pchEnd, .....);
}
*(pchEnd++) = '\0'; /* doubling the last null */
int size = pchEnd - szBuffer;
Or, you can have a unique separator (like '#' if that never appears in the
filename) and then use strtok to replace all the '#' by NULs.
> }
> else {
> iSize = text_to_add_len+1;
> szBuff = (TCHAR*)malloc(iSize*sizeof(TCHAR));
> strcpy(szBuff,text_to_add);
> //strcat(szBuff,TEXT("\0"));
> }
>
> any idea ?
>
.
- References:
- Directory is a "a file system object" ?
- From: vlg
- Re: Directory is a "a file system object" ?
- From: Igor Tandetnik
- Re: Directory is a "a file system object" ?
- From: vlg
- Directory is a "a file system object" ?
- Prev by Date: Re: pass-by-value const is part of function type signature?
- Next by Date: Re: GetSaveFileName
- Previous by thread: Re: Directory is a "a file system object" ?
- Next by thread: Re: newbie jpeg file.
- Index(es):