Thread: '*' as a command line argument

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    129

    '*' as a command line argument

    This has been bugging me since I found this out few months ago... (Don't know if this is specific to DOS/DJGPP). Anyway, how to get it as '*' to the program?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Post a short program that has the problem and I'll compile it with MS and see if it is compiler specific.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Unregistered
    Guest
    Well, at least on Unix systems, '*' etc. are handled by the shell. To prevent interpretation of them you could use quotes ('*' or "*"), or escape them with a backslash (\*).

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    > To prevent interpretation of them you could use quotes ('*' or "*"), or escape them with a backslash (\*).

    What if I want to write a dir-program (my attempt before figuring this one...)

    And here's for adrianxw: run it with '*' as an argument (not those 's) and get a directory listing.

    Code:
    #include <stdio.h>
    int main(int argc, char **argv)
    {
    	for(int i = 0;  i < argc;  i++)
    		printf("%s\n", argv[i]);
    	return 0;
    }

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Prints an asterisk. MS VC++ 6.0, Windows 2000.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    28
    You have to understand that the * is handled by the shell, and hence while using MS VC++, the * is passed to the program as it is (the shell doesn't handle it there).

    While with DOS or Unix terminals, you can use "*" quotes to put the * as it is (this is defined by the shells, so you have to comply with their instructions...there's nothing wrong with the program).

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It's all explained in the DJGPP FAQ
    http://www.delorie.com/djgpp/v2faq/faq16.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. member as default argument
    By MarkZWEERS in forum C++ Programming
    Replies: 2
    Last Post: 03-23-2009, 08:09 AM
  2. template argument
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2008, 03:01 AM
  3. function passing argument..array ?
    By jochen in forum C Programming
    Replies: 2
    Last Post: 09-30-2007, 11:53 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 09:45 PM