ricardom
Joined: 04 Nov 2016 Posts: 1
|
uC restarts after run strcpy(). |
Posted: Fri Nov 04, 2016 1:00 pm |
|
|
I'm working on a command line interpreter on a dsPIC30F4011. I want to get the args from a string that i get from the UART port. The problem: I can get my tokens without any problem, but when i try to copy them to **argv the uC restarts. Am I doing something wrong?.
Btw this function is just a test, right now i'm not intrested on free the memory after using the pointers, i just want to copy tok to a space in argv.
Code: | void parser_argv(char* inputStr)
{
char **argv = malloc(8*sizeof(char*));
char *auxStr = malloc(BUFFER_SIZE * sizeof(char*));
unsigned int argc = 0;
strcpy(auxStr,inputStr);
char *tok = strtok (auxStr,delimiters);
if(tok != NULL){
fprintf(PC_UART,"First Val %s\n",tok);
while(tok !=NULL){
tok = strtok (NULL, delimiters);
strcpy(argv[argc],tok);
fprintf(PC_UART,"token %s %s\n",argv[argc],tok);
argc++;
}
}
} |
Thanks. |
|