Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to solve your problem in different steps,</p> <p>The first step is to check how many tokens you have in your input string to be able to allocate enough space to store an array of tokens.</p> <p>Then you should extract the tokens of the input strings in your tokens string array. To extract the tokens from your input string, you can use the <code>strtok</code> function from <code>&lt;string.h&gt;</code>.</p> <p>Finally you can use your tokens however you want, like converting them to <code>long</code> in your case.</p> <p>EDIT: given the requirements, here is a small implementation of what you could do. I don't check the returns of the malloc, you maybe should do it. </p> <pre><code>int main(int argc, char** argv) { int i; char* input_string = /* your input string for somewhere */; char** tokens; int tokens_count = 0; char* input_ptr = input_string; char* tmp_token; size_t tmp_token_length; // count the occurences of your separtor to have the number of elements for(; input_ptr[tokens_count]; input_ptr[tokens_count] == ',' ? tokens_count++ : input_ptr++); if(tokens_count == 0) { // no tokens found, what do you want to do here ? } else { // build our tokens array tokens = malloc(sizeof(*tokens) * tokens_count); i = 0; tmp_token = strtok(input_string, ','); while(tmp_token != NULL) { tmp_token_length = strlen(tmp_token); if(tmp_token_length != 0) { tokens[i] = malloc(tmp_token_length); strcpy(tokens[i], tmp_token); } else { tokens[i] = NULL; } i++; tmp_token = strtok(input_string, ','); } // populate your array of arrays of integers long** m = malloc(sizeof(long*) * tokens_count); for(i=0; i&lt;tokens_count; i++) { char* tmp_token = tokens[i]; if(tmp_token == NULL) { m[i] = NULL; } else { m[i] = malloc(sizeof(long)); m[i][0] = strtol(tmp_token, NULL, 10); } } } } </code></pre> <p>However, you should probably change your data structure by using structures instead of a massive array.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload