Issue with C template reading EOL


I am working on the question of the week Sandpile addition using C and found that the start off C template is unable to read the expected input.

for (int i = 0; i < n; i++) {
    char row[n+1];
    fgets(row, n+1, stdin);


Upon closer look it is due to the stdin is providing Windows EOL \r\n and the first call to fgets read the \r, and left the \n being read by 2nd call to fgets.

It is quite a common issue especially for Community question since I have been meeting it at Clash as well. Of course for normal question you can always provide a workaround, but you will know how annoying it would be when you are racing the clock.

Higher Level language like java is able to distinguish it for you right away.

Please see if it is treated as an issue.

There’s no \r here, but n+1 is too short to store the n characters, \n, and the final \0.

I’ve changed the stub generator input to have row[13] instead of row[n+1].