Ok, what I would do: I would first read in the whole line, after that I would make sure we are dealing 1 or more int-variables. Now after that I would count the number of commas, as you may notice, the number of variables equals the number of commas+1. For that you only need 1 loop that goes something like this (pseudocode)
Code:
Read line
if line is creating variables // Is it a line creating variables??
// We want 1 because we know we have at least 1 variable
variableCount = 1
for i = offsetToFirstVarName; i<sizeOfLine || line[i] == ';'; i++
if line[i] == ','
variableCount++
That's how i would do it.