title: How to extract spaced numbers from a string into a float array only using 1D array?
body: <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #define SIZE 20
  
  int main()
  {
    int num;
    float val[SIZE];
    int size_r;
    int size_j;
    int size;
    int i=0;
    int j;
    char mat[SIZE];
    int key;
  
    printf("Enter size of rows: ");
    scanf("%i",&amp;size_r);
    getchar();
    printf("Enter size of columns: ");
    scanf("%i",&amp;size_j);
    getchar();
    size=size_r*size_j;
  
    printf("Please input matrix (one row at a time and spaced numbers): ");
    for (num=0;num&lt;size_r;num++)
    {
      fgets(mat,SIZE,stdin);
      for (num=0;num&lt;SIZE;num++)
      {
        if (mat[num]==' ')
        {
           val[i]=atof(mat);
           i++;
        }
      }
    }
    for (num=0;num&lt;SIZE;num++)
    {
      printf("%.2f\t",val[num]);
    }
  </code></pre>
  
  <p>I have initialized some variables that I will need, but the code is not complete yet because of the following problem. For example, when I input '12 23 34', I can only extract 12.00 and every other element fills with 0.00. Any help?</p>