I am working on a project for my programming class, but I am having issues with getting values from a text file and assigning them to variables in my code. I have multiple lines of numbers in my text file, and each line tends to vary in the amount of floats and integers.

Specifically:
15 20 50 1.0 0.0
5 4 5.0
6 4 5.0
7 4 5.0
8 4 5.0
-1

There are several data sets as the one above.
The first line consists of matrix and parameters for processing the values within the matrix, there are 5 values for the start of each data set. Afterwards there are several lines of 3 values. Those are values that will be put into the matrix (m,n,value). So the second line for example: array[5][4]=5.0.
The last line of each data is always a -1. This flags the end of the data set.

I have to create matrices multiple times, and I just need help scanning in the numbers.
Here's what I have so far, but It's not working:

Code:
while(fscanf(fin,"%d %d %d %lf %lf",&m,&n,&itmax,&eps,&evalue) == 5)
{
    /*some printing commands*/


    while(fscanf(fin,"%d",&i)==1)
    {
        if(i != -1)
        {
            fscanf(fin,"%d %lf",%j,%value);
        }
        else{break;}
    }
}