How to scan txt file for data and store in arrays in C?
<p>I'm trying to read a text file containing both strings and numbers and save into their respective arrays. This is the contents text file I'm trying to read</p>

<pre><code>Ryan, Elizabeth     62
McIntyre, Osborne   84
DuMond, Kristin     18
Larson, Lois        42
Thorpe, Trinity     15
Ruiz, Pedro         35
Ali, Mohammed       60
Vashti, Indura      20
</code></pre>

<p>I need to save the last name, first name and the age of the repescitve person in parallel arrays. (so I need to discard the comma when reading).
This is what I have so far.</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

int main(int argc, char *argv[])
{
    char line[100][41];
    char junk[100];
    int i;
    FILE *file = fopen(argv[1], "r");

    if(!file) {
        printf("Could not open file. Exiting application.");
        return 1;
    }

    for(i=0; i&lt;100; i++)
    {
        fscanf(file, "%[^\n]", line[i]); //Get text
        fscanf(file,"%[ \n\t\r]s",junk); //Remove any 'white space' characters
    }

    fclose(file);

    for (i=0; i&lt;30; i++)
        printf("%s\n",line[i]);

    return 0;
}
</code></pre>

<p>I've passed the file argument in IDE. I get a lot of special characters at the end of output.</p>

<pre><code>Ryan, Elizabeth         62
McIntyre, Osborne       84
DuMond, Kristin         18
Larson, Lois            42
Thorpe, Trinity         15
Ruiz, Pedro             35
Ali, Mohammed           60
Vashti, Indura          20
┌

 t╠╠

$

M

v
9 Rì
xá

╚

±
t/╗₧8
¿≡`
   Tq töq t4≤`


ÿv
h((((                  Hääääääääääüüüüüüéééééé 
</code></pre>

<p>Why am I reading all those special characters? And how can I discard the comma and save into three different arrays?</p>