Thread: separating line of arrays into array of arrays

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    Question separating line of arrays into array of arrays

    If anyone can help -much appreciate

    I want to take a line of input from the user using an array of cmd[100]; then take that input and separating them out with spaces as a delimiter into an array of arrays cmdarg[][].

    I think the code below does separate them out, but for some reason i can't cout anything other than cmdarg[0]. Nothing else comes out???

    this will be use as a command line with arguments in a program, but i am having a tough time separating the commands and arguments into its own vector of arrays. Is better to do it with strings??? I am not sure of what to use?

    thanks in advance





    //partial codes
    char *c[1000];
    char cmd[100];
    char cmdarg[1000][1000];
    int status,i=0,j=0,k=0;


    cin.ignore();

    cout<<"Commands:";
    cin.getline(cmd,100);

    for(i=0;i<100;i++){
    if(cmd[i]==' '){//space
    j++; //increase row
    k==-1;//reset column
    }
    if(cmd[i]!=' '){//put in next column
    cmdarg[j][k]=cmd[i];//insert in array of arrays
    }
    k++;//increase column
    }
    Last edited by robocop; 10-19-2001 at 06:27 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 02:31 PM
  3. delete array of arrays
    By tmod in forum C++ Programming
    Replies: 4
    Last Post: 04-17-2007, 03:37 PM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. Array pointers to Multi-Dimensional Arrays
    By MethodMan in forum C Programming
    Replies: 3
    Last Post: 03-18-2003, 09:53 PM