Results 1 to 2 of 2
  1. #1
    New Lounger
    Join Date
    Dec 2009
    Location
    Wolfville, Nova Scotia, Canada
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    I am trying to save a set of strings (Favorite descriptions + the associated URL) to a text file. However the saving process seems to truncate the string. So if the string to be saved is "C:\User\UserName\Favorites\Blogs & Fora\Windows Lounge; http://lounge.windowssecrets.com", what gets saved is just "C:\User\UserName\Favorites\Blogs & Fora"

    Does anyone have any thoughts about what might be causing this? The code is
    CStdioFile fFavs;
    if (fFavs.Open(sFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText )) {
    for (i=0; i<nMax; i++) {
    pItem = getdatafromarray(i);
    CString sItem;
    sItem.Format(_T("Ts; %s\n"), pItem->FavPath(), pItem->FavURL()); // (both FavPath() and FavURL() return strings)
    sItem.Trim();
    fFavs.WriteString((LPCTSTR) sItem.GetBuffer());
    }
    fFavs.Close();

  2. #2
    2 Star Lounger
    Join Date
    Dec 2009
    Location
    Manchester, United Kingdom
    Posts
    116
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Hi Diverron. Long time no reply, bet you've worked it out yourself. I'm not a C programmer, but Unicode strings are two bytes per character, normal C strings one byte. So somewhere along the line it looks like C is counting the characters in the string and writing that many bytes, so output is only half the string. Need to make sure everything is either Unicode or Standard.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •