A
alef
Hi,
I have the following code which is driving me crazy. I compile it on
MacOSX and it keeps crashing upon entering a command in the program
(ran trough gdb)
[command]pwd
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x000105bc in parse_commands (command=0xbffe70e4 "pwd") at
/Users/alefveld/Projects/project1/client.c:198
198 while((argv[i++]=strtok(command,""))) {
(gdb) quit
this is the conflicting piece of code. i suspect it's in the ptr to ptr
because when working with a normal ptr no problem occurs. i just don't
want to make a dozen strtok calls. i would like all the arguments of a
single command to be split up in tokens and put nicely in my **argv. do
i need to initialize anything? is the char *ptr strtok giving me not
correct? do i need to cast it ?
ps *command is a '\0' ended string.
int parse_commands(char *command)
{
int i=0, argc=0;
char **argv={0}; // initialize everything to NULL
connection_index *tmp=head; // not relevant here
/* Split up command in tokens */
while((argv[i++]=strtok(command,""))) {
command=NULL;
argc++;}
/* A command always exists of 2 or more arguments. */
if(argc<=1) return -1;
thanks a lot,
Rgds,
Alef
I have the following code which is driving me crazy. I compile it on
MacOSX and it keeps crashing upon entering a command in the program
(ran trough gdb)
[command]pwd
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x000105bc in parse_commands (command=0xbffe70e4 "pwd") at
/Users/alefveld/Projects/project1/client.c:198
198 while((argv[i++]=strtok(command,""))) {
(gdb) quit
this is the conflicting piece of code. i suspect it's in the ptr to ptr
because when working with a normal ptr no problem occurs. i just don't
want to make a dozen strtok calls. i would like all the arguments of a
single command to be split up in tokens and put nicely in my **argv. do
i need to initialize anything? is the char *ptr strtok giving me not
correct? do i need to cast it ?
ps *command is a '\0' ended string.
int parse_commands(char *command)
{
int i=0, argc=0;
char **argv={0}; // initialize everything to NULL
connection_index *tmp=head; // not relevant here
/* Split up command in tokens */
while((argv[i++]=strtok(command,""))) {
command=NULL;
argc++;}
/* A command always exists of 2 or more arguments. */
if(argc<=1) return -1;
thanks a lot,
Rgds,
Alef