Thread: Those pesky command lines...

  1. #1
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273

    Unhappy Those pesky command lines...

    Hello,

    Just a quick question. A program I've made doesn't take kindly to long filenames when passed to it by Explorer (The little tyke loves sellotaping it all together with speech marks yet MS decided CreateFile shouldn't parse them out ). Is there a simple way of fixing the string?

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    So you have a string like ' "file with long filename.txt" ' and you want it to become 'file with long filename.txt'? Try this:

    Code:
    char * RemoveQuotes(char *lpString)
    {
        lpString++;
        lpString[lstrlen(lpString)-1]=0;
        return lpString;
    }
    Approximate, and likely will cause a memory leak, or access violation now that I think about it. Hmmm.

    Code:
    void RemoveQuotes(char *lpString)
    {
        int size=lstrlen(lpString);
    
       for (int i=0;i<size;i++)
       {
           lpString[i]=lpString[i+1];
       }
       lpString[size-2]=0;
    }
    That should work fine I think.
    [email protected]
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ridding Myself of a Pesky Virus/Spyware/Whatever
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 05-22-2006, 12:12 PM