Getting the files from OFN_ALLOWMULTISELECT

This is a discussion on Getting the files from OFN_ALLOWMULTISELECT within the Windows Programming forums, part of the Platform Specific Boards category; I'm using this code to grab the files: Code: char szFiles[1024], szFileTok[260]; char *p; lstrcat(szFiles, lpstrFile); // ofn.lpstrFile = lpstrFile; ...

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, Mxico
    Posts
    308

    Question Getting the files from OFN_ALLOWMULTISELECT

    I'm using this code to grab the files:
    Code:
    char szFiles[1024], szFileTok[260];
    char *p;
    lstrcat(szFiles, lpstrFile); // ofn.lpstrFile = lpstrFile;
    p = lpstrFile;
    while(*p)
    {
        p += lstrlen(p) + 1;
        wsprintf(szFileTok, "|%s", p);
        lstrcat(szFiles, szFileTok);
    }
    My problem is that szFiles returns:
    C:\joel|keygen.exe|exec.c|
    Why the garbage in the begining?

    Thanks
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,672
    > Why the garbage in the begining?
    Because strcat() appends to whatever string is there, and since you don't initialise your string, you end up with random garbage at the beginning.

    Use strcpy() to copy in the first string, then cat afterwards.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, Mxico
    Posts
    308
    Ah...ditto

    Thanks
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 10:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 01:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21