Thread: command line inputs causing strange errors, what's going on?

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by quzah View Post
    I would be surprised if the percentage of people that have used a computer in the past decade, that have used a command line, broke the single digit range.
    Quzah.
    From my days learning Pascal during lunch hours at work: "How in Peter's skinny butt do you ever intend to program a computer you don't know how to operate?"

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by CommonTater View Post
    No, he'll be getting the first filename that matches ... if he uses a batch file ... for () in * he will get them all in turn. He only gets one file name because he's only running the program once.
    Don't be ridiculous.
    Code:
    C:\Users\tabstop>copy con wild.c
    #include <stdio.h>
    int main(int argc, char *argv[]) {
        printf("argc = %d\n", argc);
        int i;
        for (i = 0; i < argc; i++) {
            printf("argv[%d]=%s\n", i, argv[i]);
        }
        return 0;
    }
    ^Z
            1 file(s) copied.
    
    C:\Users\tabstop>gcc -o wild.exe wild.c
    
    C:\Users\tabstop>wild *i
    argc = 4
    argv[0]=wild
    argv[1]=gsview32.ini
    argv[2]=ntuser.ini
    argv[3]=psv.ini

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by tabstop View Post
    Don't be ridiculous.
    Code:
    C:\Users\tabstop>copy con wild.c
    #include <stdio.h>
    int main(int argc, char *argv[]) {
        printf("argc = %d\n", argc);
        int i;
        for (i = 0; i < argc; i++) {
            printf("argv[%d]=%s\n", i, argv[i]);
        }
        return 0;
    }
    ^Z
            1 file(s) copied.
    
    C:\Users\tabstop>gcc -o wild.exe wild.c
    
    C:\Users\tabstop>wild *i
    argc = 4
    argv[0]=wild
    argv[1]=gsview32.ini
    argv[2]=ntuser.ini
    argv[3]=psv.ini
    Harumph... I realized after posting... My bad.

  4. #19
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    Quote Originally Posted by CommonTater View Post
    Type WIN+R in the Run dialog type CMD and click OK... now type cmd /? and start reading...
    The guys are steering you in the right direction.

    If you put a * on your command line it will be replaced by the first filename it finds.
    Ah, running cmd /? and then pressing enter a couple of times lead me to a text telling me some characters needed to be within "" when printed to console. & was among them, * was not, but ' was so I assume * is mistaken for '. I guess that explains the most of it. The input is taken as * but when printed to console it is read as a command by the console. Thank you all!

    tabstop: I am 100% sure. I tested this before posting here. I had a program printing argv[n] where n went beyond the list of suitable files. When it went beyond, it just printed zeroes in those spots...
    Sorry, Im an idiot. Checked again since you posted code here to show you my code, and I did get several files listed.
    Last edited by Hear.Me.ROAR; 07-11-2011 at 05:57 PM.

  5. #20
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    Quote Originally Posted by tabstop View Post
    Don't be ridiculous.
    Code:
    C:\Users\tabstop>copy con wild.c
    #include <stdio.h>
    int main(int argc, char *argv[]) {
        printf("argc = %d\n", argc);
        int i;
        for (i = 0; i < argc; i++) {
            printf("argv[%d]=%s\n", i, argv[i]);
        }
        return 0;
    }
    ^Z
            1 file(s) copied.
    
    C:\Users\tabstop>gcc -o wild.exe wild.c
    
    C:\Users\tabstop>wild *i
    argc = 4
    argv[0]=wild
    argv[1]=gsview32.ini
    argv[2]=ntuser.ini
    argv[3]=psv.ini
    You're right. My fault. Sorry again
    Last edited by Hear.Me.ROAR; 07-11-2011 at 06:02 PM.

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Hear.Me.ROAR View Post
    Ah, running cmd /? and then pressing enter a couple of times lead me to a text telling me some characters needed to be within "" when printed to console. & was among them, * was not, but ' was so I assume * is mistaken for '. I guess that explains the most of it. The input is taken as * but when printed to console it is read as a command by the console. Thank you all!
    The characters as given are for quoting in filenames rather than starting a new argument. (I think I said quoting earlier, so that's my fault.) EDIT: According to http://www.microsoft.com/resources/d....mspx?mfr=true, the escape character is ^, which I had forgotten. EDIT EDIT: ^ may be the escape character, but it doesn't work on * or ?.
    tabstop: I am 100% sure. I tested this before posting here. I had a program printing argv[n] where n went beyond the list of suitable files. When it went beyond, it just printed zeroes in those spots...
    Did it print argv, or did it print atoi(argv[n])? Not quite the same thing....
    Last edited by tabstop; 07-11-2011 at 06:28 PM.

  7. #22
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    Yeah, the later, atoi, that is why I got the wrong output according to what should be shown (a list of files). Read the other posts, I corrected them and gave you the cred for that path of the discussion. Once again, completely my fault :/

  8. #23
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Hear.Me.ROAR View Post
    Yeah, the later, atoi, that is why I got the wrong output according to what should be shown (a list of files). Read the other posts, I corrected them and gave you the cred for that path of the discussion. Once again, completely my fault :/
    Not a problem. (But if you wonder why we often ask for actual code and actual input and actual output -- this is why. Not that you're trying to deceive us, but if we're getting almost-but-not-quite the actual information, that leads to almost-but-not-quite help on the other end.)

  9. #24
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    Quote Originally Posted by tabstop View Post
    Not a problem. (But if you wonder why we often ask for actual code and actual input and actual output -- this is why. Not that you're trying to deceive us, but if we're getting almost-but-not-quite the actual information, that leads to almost-but-not-quite help on the other end.)
    Still not sure why it reacts on *, it not listed in either cmd as a command nor the msdn-link

  10. #25

  11. #26
    Registered User
    Join Date
    Jun 2011
    Posts
    30
    tabstop: You're the man!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ templated function causing linking errors
    By coder123321 in forum C++ Programming
    Replies: 7
    Last Post: 11-18-2010, 11:38 AM
  2. copy constructor causing errors
    By yahn in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2005, 02:11 PM
  3. Taking inputs at Command Line
    By Stephenf in forum C++ Programming
    Replies: 1
    Last Post: 09-28-2005, 02:33 AM
  4. Header inclusion causing errors
    By cjschw in forum C++ Programming
    Replies: 12
    Last Post: 08-11-2004, 03:48 PM
  5. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 10:45 AM