M
miketigerwoods
I'm having problems where I need to parse a command line, and place
each token from strtok() into an array. I've read here:
http://www.phim.unibe.ch/comp_doc/c_manual/C/CONCEPT/arrays.html (at
bottom) that you can access a char[][] by doing char and getting the
string. However when I try the code below I get
error: invalid use of array with unspecified bounds
whenever argv is accessed. It is declared in main() as:
char argv[ARGV_LENGTH][ARGV_LENGTH]; /* ARGV_LENGTH is a const int of
64 */
This is pretty much my first time with C, I'm usually using Java and a
little C++. Any help is appreciated.
Thanks,
Mike
void parse_cmdline(char cmdline [], char argv [][])
{
char * command;
int i = 1;
command = strtok(cmdline, DELIMITERS);
argv[0] = malloc(sizeof(char)*(strlen(command)+1));
strcpy(argv[0],command);
while (command != NULL) {
printf("%s\n", command);
command = strtok(NULL, DELIMITERS);
argv = malloc(sizeof(char)*(strlen(command)+1));
strcpy(argv,command);
i++;
}
}
each token from strtok() into an array. I've read here:
http://www.phim.unibe.ch/comp_doc/c_manual/C/CONCEPT/arrays.html (at
bottom) that you can access a char[][] by doing char and getting the
string. However when I try the code below I get
error: invalid use of array with unspecified bounds
whenever argv is accessed. It is declared in main() as:
char argv[ARGV_LENGTH][ARGV_LENGTH]; /* ARGV_LENGTH is a const int of
64 */
This is pretty much my first time with C, I'm usually using Java and a
little C++. Any help is appreciated.
Thanks,
Mike
void parse_cmdline(char cmdline [], char argv [][])
{
char * command;
int i = 1;
command = strtok(cmdline, DELIMITERS);
argv[0] = malloc(sizeof(char)*(strlen(command)+1));
strcpy(argv[0],command);
while (command != NULL) {
printf("%s\n", command);
command = strtok(NULL, DELIMITERS);
argv = malloc(sizeof(char)*(strlen(command)+1));
strcpy(argv,command);
i++;
}
}