I have to take integer input to an integer array. I have to identify the newline also in input. To be more clear, I have an example. The input I am giving is:-
2
though you mention c++ here is something that i often use to read in an array of doubles from a file
char line[512+1];
unsigned int row = 0 ;
unsigned int col = 0 ;
while( fgets(line, sizeof(line), file) )
{
col = 0 ;
tempChr = strtok(line, delimters);
// ignore blank lines and new lines
if ( tempChr[0] == '\n' )
{
continue ;
}
tempDbl = atof(tempChr);
data[row*numCols+col] = tempDbl ;
for(col = 1 ; col < numCols ; ++col)
{
tempDbl = atof(strtok(NULL, delimters));
data[row*numCols+col] = tempDbl;
}
row = row + 1;
if( row == numRows )
{
break ;
}
}