0

I'm currently concantenating an array like so...

int _tmain(int argc, _TCHAR* argv[])
{
    //create buffer to receive path
    WCHAR pathbuf[MAX_PATH];
    //get path into buffer
    DWORD pathlen = GetCurrentDirectoryW(MAX_PATH,pathbuf);
    //append file name to buffer
    pathbuf[pathlen++] = '\\';
    pathbuf[pathlen++] = 'f';
    pathbuf[pathlen++] = 'i';
    pathbuf[pathlen++] = 'l';
    pathbuf[pathlen++] = 'e';
    pathbuf[pathlen++] = '.';
    pathbuf[pathlen++] = 'e';
    pathbuf[pathlen++] = 'x';
    pathbuf[pathlen++] = 't';
    pathbuf[pathlen++] = '\0';

    std::wcout << pathbuf << std::endl;
    std::cout << pathlen << std:: endl;

    return 0;
}

How can I do this a little less cumbersome?

2
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by Suzie999
0

Thanks for the suggestion, I ended up after following links from your offer to use wcsncat

int _tmain(int argc, _TCHAR* argv[])
{
    //create buffer to receive path
    WCHAR pathbuf[MAX_PATH];
    //get path into buffer
    DWORD pathlen = GetCurrentDirectoryW(MAX_PATH,pathbuf);
    //append file name to buffer
    WCHAR * filename = L"\\file.ext\0";

    wcsncat( pathbuf, filename, 9 );

    std::wcout << pathbuf << std::endl;
    std::cout << pathlen << std:: endl;

    return 0;
 }

Is this the correct usage? I mean with "filename 9" will this result have terminating character?

(edit) OK I think I found solution, please advise if you think it incorrect usage.

wcsncat( pathbuf, filename, wcslen(filename));

Thank you for help.

sorry, I can not find button to mark as solved.

Edited by Suzie999: info

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.