command line arguments

Discussion in 'C++' started by Ashe Corven, May 8, 2004.

  1. Ashe Corven

    Ashe Corven Guest

    i need help pretty bad for this

    from the command line

    >csend string1 4233 "string2"


    how can i copy string1, or string2 to a char* or a string.


    for argument 4 (string2)

    char temp[256];
    strcpy(temp, argv[4]);

    this doesn't work
    ------------
    int i;
    char temp[256];
    for(i=1; argv[4] != '"'; ++i)
    {
    temp = argv[4];
    }
    temp = '\0'

    neither does this - gives a seg fault on this line
    for(i=1; argv[4] != '"'; ++i)

    how do i do it. and why don't these techniques work
    Ashe Corven, May 8, 2004
    #1
    1. Advertising

  2. Ashe Corven

    David Harmon Guest

    On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
    <cfitzgib@@bigpond.net.au> wrote,
    >from the command line
    >
    >>csend string1 4233 "string2"

    >
    >how can i copy string1, or string2 to a char* or a string.
    >
    >
    >for argument 4 (string2)
    >
    >char temp[256];
    >strcpy(temp, argv[4]);


    Main reason being that string2 is argv[3] ?


    int main(int argc, char *argv[])
    {
    cout << "argc = " << argc << '\n';
    for(int argx = 0; argx < argc; argx++) {
    cout << "argv[" << argx << "] = \"" << argv[argx] << "\"\n");
    }
    return 0;
    }
    David Harmon, May 8, 2004
    #2
    1. Advertising

  3. Ashe Corven

    Ashe Corven Guest

    oh shit
    haha
    "David Harmon" <> wrote in message
    news:...
    > On Sat, 08 May 2004 15:42:03 GMT in comp.lang.c++, "Ashe Corven"
    > <cfitzgib@@bigpond.net.au> wrote,
    > >from the command line
    > >
    > >>csend string1 4233 "string2"

    > >
    > >how can i copy string1, or string2 to a char* or a string.
    > >
    > >
    > >for argument 4 (string2)
    > >
    > >char temp[256];
    > >strcpy(temp, argv[4]);

    >
    > Main reason being that string2 is argv[3] ?
    >
    >
    > int main(int argc, char *argv[])
    > {
    > cout << "argc = " << argc << '\n';
    > for(int argx = 0; argx < argc; argx++) {
    > cout << "argv[" << argx << "] = \"" << argv[argx] << "\"\n");
    > }
    > return 0;
    > }
    >
    Ashe Corven, May 8, 2004
    #3
  4. In message <fd7nc.27672$>, Ashe Corven
    <cfitzgib@?.net.au.invalid> writes
    >i need help pretty bad for this
    >
    >from the command line
    >
    >>csend string1 4233 "string2"

    >
    >how can i copy string1, or string2 to a char* or a string.
    >
    >
    >for argument 4 (string2)
    >
    >char temp[256];
    >strcpy(temp, argv[4]);
    >
    >this doesn't work
    >------------
    >int i;
    >char temp[256];
    >for(i=1; argv[4] != '"'; ++i)
    >{
    > temp = argv[4];
    >}
    >temp = '\0'
    >
    >neither does this - gives a seg fault on this line
    >for(i=1; argv[4] != '"'; ++i)
    >
    >how do i do it. and why don't these techniques work
    >
    >


    The four command line arguments are pointed to by:
    argv[0] // pointer to the name of the program
    argv[1] // pointer to string1
    argv[2] // pointer to 4233
    argv[3] // pointer to string2

    Remember that in C (and C++) we count from 0.


    --
    Francis Glassborow ACCU
    Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
    For project ideas and contributions: http://www.spellen.org/youcandoit/projects
    Francis Glassborow, May 8, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Kay
    Replies:
    1
    Views:
    482
    J├╝rgen Exner
    May 18, 2004
  2. Ahmed Moustafa

    Parser for command line arguments?

    Ahmed Moustafa, Aug 21, 2003, in forum: Java
    Replies:
    0
    Views:
    383
    Ahmed Moustafa
    Aug 21, 2003
  3. SC
    Replies:
    2
    Views:
    656
    Michiel Salters
    May 5, 2004
  4. Ian Malone
    Replies:
    8
    Views:
    397
    Chris Croughton
    Feb 18, 2005
  5. Replies:
    4
    Views:
    1,708
    Terry Hancock
    Apr 23, 2005
Loading...

Share This Page