I declare char ** arr and the routine parse in the include file
char **arr;
void parse( char *record, char *delim, char **tarr);
memory is allocated for arr in main
for (i = 0; i < 100; i ++){
if( (arr = (char*)calloc(12, sizeof(char))) == NULL)
printf("no memory allocated for arr\n");
}
still in main I get a line of char
fgets(tmp,1024,action);
and sent it to parse
parse(tmp,",",(char**) arr);
parse is defined in another c file and looks like this
I get a "could not access memory" error at strcpy(tarr[fld],p).
Somebody please tell me what's wrong?
thanks
char **arr;
void parse( char *record, char *delim, char **tarr);
memory is allocated for arr in main
for (i = 0; i < 100; i ++){
if( (arr = (char*)calloc(12, sizeof(char))) == NULL)
printf("no memory allocated for arr\n");
}
still in main I get a line of char
fgets(tmp,1024,action);
and sent it to parse
parse(tmp,",",(char**) arr);
parse is defined in another c file and looks like this
Code:
void parse( char *record, char *delim, char **tarr)
{
char *p;
int fld=0;
if ( (p = (char *) calloc(12, sizeof(char))) == NULL)
printf(""no memory for p");
p = strtok(record,delim);
while(p)
{
strcpy(tarr[fld],p);
fld++;
p=strtok('\0',delim);
}
}
Somebody please tell me what's wrong?
thanks