EvilZone
Programming and Scripting => C - C++ => : 0poitr December 31, 2013, 02:04:43 PM
-
struct split *stringSplit (char *str, char *delim)
{
char **token_array;
*token_array = NULL;
allocPtrs (token_array);
char *token = str, *saveptr;
unsigned int bulk = 1, j;
for (j=0; ; token=NULL) {
token = strtok_r (token, delim, &saveptr);
if (token) {
if (j == bulk*CHAR_PTRS) {
allocPtrs (token_array);
bulk++;
}
*token_array+j = calloc (1, strlen (token)+1);
if (! *token_array+j )
error ("calloc");
strcpy (*token_array+j, token);
j++;
}
else break;
}
struct split *s_arr = calloc (sizeof(struct split), 1);
s_arr->num = j;
s_arr->token_array = token_array;
return s_arr;
}
stringlib.c: In function ‘stringSplit’:
stringlib.c:50:28: error: lvalue required as left operand of assignment
*token_array+j = calloc (1, strlen (token)+1);
^
The function is meant to split the string by the delimiters and return an array of substring tokens.
What's going wrong? GCC's considering *token_array+j as a constant. WHY! I'm starting to loose mental sanity >:(
-
Try to use () in your pointer+j
*(token_array+j) = calloc (1, strlen (token)+1);
Staff note: try to use the edit button next time.