Parsing string with multiple delimiters
<p>How could I parse a text file like so:
DISCLAIMER: I CAN NOT ASSUME I KNOW THE CONTENT OF THE TEXT FILE THIS IS JUST A EXAMPLE TEXT FILE</p>

<pre><code>10X16 de4 dw9 ds11 g10,7 M3,4 h6,5 p2,2 M8,5 G2,10
12X20 de7 dw10 dn13 g9,10 M7,8 h6,5 p2,2 M8,5 G2,10
</code></pre>

<p>What this text file is saying is there is a room with the dimensions of <code>10X16</code>, a door on the east wall <code>de4</code> in the fourth position, <code>g10,7</code> means there is a small gold at position <code>10Y</code> and <code>7X</code>...I do not want to store any letters, the letters are there just to inform me of what the numbers being read are for. I want to store the numbers into <code>int</code> variables according to what it is is: gold, monster, potion, etc.</p>

<p>Where I need to store <code>10</code> as a <code>Y</code> value and <code>16</code> as an <code>X</code> value, and the other elements after the dimensions are stored in different variables.</p>

<p>Heres my code:</p>

<pre><code>int main(int argc, char *argv[]) {
    //open file and read
    FILE *file = fopen(argv[1], "r");
    char line[150];
    char *dim;
    int X = 0;

    while (fgets(line, 150, file) != NULL) {
        dim = strtok(line, "X");
        X = atoi(dim);
        printf("%d\n", X);

        //parse other elements here?
        ...
    }
    fclose(file);
    return 0;
}
</code></pre>

<p>So for example I want <code>10</code> in variable <code>char *roomY</code> and <code>16</code> in <code>char *roomX</code>, and <code>4</code> to be stored in variable <code>char *eastDoor</code>, which will all be converted to <code>int</code> values later on.</p>

<p>ALSO elements like <code>g10,7</code> I want <code>10</code> to be stored as a <code>Y</code> value and <code>7</code> as a <code>X</code> value for that element.</p>

<p>I should also add that the letters should be used to determine what the value is.
Maybe a <code>if (string[i] = "d")</code> path for example to be used.</p>

<p>What I have tried is using <code>strtok(roomY, "X")</code> to get <code>X</code>, and then <code>int Y = atoi(roomY)</code> to convert the <code>char</code> to an <code>int</code> value. That works for just the <code>10</code>, but the rest of the file im having trouble parsing correctly. Is there a more efficient way to do this?</p>