Thread: Handling spaces in command line arguments

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User starkhorn's Avatar
    Join Date
    Sep 2003
    Posts
    21

    Handling spaces in command line arguments

    Hi Folks,

    A question which I hope isn't too silly or naive but one that is pulling my hair out.

    I'm passing arguments to main, no big deal. The first argument that I'm passing is a directory where input txt files need to be processed by my program. Again nothing complicated or anything.

    THe problem is windows and specfically spaces that it allows in directory names.

    For example, I call my program with the below command lines.

    Code:
    C:\AutoChar\\autochar_classes.exe C:\Documents and Settings\adminstrator\My documents\turn57
    Notice the spaces in the Documents and Settings directory and My Documents.

    Now I only want to have 1 extra element in argv but because of the spaces, it adds 4 of them. As below:-

    Code:
    argc = 5
    argv[0] = C:\AutoChar\autochar_classes.exe
    argv[1] = C:\Documents
    argv[2] = and
    argv[3] = Settings\adminstrator\My
    argv[4] = documents\turn57
    So is there any syntax within DOS that I can use so that the spaces are ignored by argv and that it puts the entire command line argument at argv[1] (spaces and alll).

    If not in DOS, then is there something that I can do within c++.

    My problem is that I will have 2 command line arguments. One with be the input directory for input files and the 2nd command line argument will be the directory for output files. Both may contain white space in their names and I won't know for sure when one begins and one ends.

    Any suggestions ?

    Cheers
    Starkhorn
    Last edited by starkhorn; 11-11-2004 at 05:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. signal handling and exception handling
    By lehe in forum C++ Programming
    Replies: 2
    Last Post: 06-15-2009, 10:01 PM
  2. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  3. event handling is serialized in MS Visual Studio C++ 2005 ??
    By mynickmynick in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2008, 04:47 AM
  4. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  5. Strategies for Handling Command Line Arguments
    By thetinman in forum C++ Programming
    Replies: 7
    Last Post: 04-09-2008, 08:18 AM