title: How to read numbers separated by commas where the input is of unknown length?
body: <p>My input for the problem has to look like this : 3,5,9,6,2,8.
  I have no way to know how many elements the sequence is going to have so the array should be dynamic.</p>
  
  <p>I've tried reading each number using getchar and then reallocate memory as I'm adding elements into the array but getchar reads the ASCII value of only one digit at a time so if I put 11,12- it would read 1 1 1 2. It also only stored the first 1 into the array.</p>
  
  <pre><code>int main(int argc, char *argv[]) {
      int initialSize = 100;
      int intCount = 0;                      
      int *sequence = safeMalloc(initialSize);
      char c = getchar();
  
      // reads first DNA sequence dynamically
      while (c != '\n') {
          if(c==',')
          {
              c=getchar();
          }
          printf("%d\n",c);
          if (intCount &lt; initialSize) {
              sequence[intCount] = c-'0';
              intCount++;
              c = getchar();
          } else {
              initialSize = initialSize * 2;
              sequence = realloc((char*) sequence, sizeof(char*) * initialSize);
              sequence[intCount] = c-'0';
          }
      }
      for(int i=0;i&lt;strlen(sequence);i++)
      {
          printf("%d\n", sequence[i]);
      }
  } // EDIT: Adrian added this as it was clearly just a 'typo' to omit it.
  </code></pre>
  
  <p>I substracted the ASCII value of 0 to get the actual number but it only read one digit at a time when I need to read the whole number ( ex: 11 not 1,1).
  Is there a way to read the input without using getchar as long as I don't know how big the input is.</p>