It's not homework. It's just for a game online, for fun. It does give you a list of numbers in a row, and $n is the number of numbers that are in that row. I've solved the game through the code I have, but now I'm trying to shorten it as much as possible and use better methods to accomplish the task. It's just a fun learning thing, and can be done in any way you choose. The code I provided was the way I solved it, but I know there are other possibilities and better options which is why I'm looking for help on some of it.
I don't really know why I would need $n, unless like you said to go through that many iterations instead of pulling in all numbers. I know it mentions in the instructions something about it pulling in all numbers and that you can change it. I have tried to look in to the STDIN and those functions being used (they were provided to begin the game basically) but haven't found anything that really makes me understand how it's working. I tried the fscan code and it makes my code fail every test case, even though I'm not calling $n anywhere in my code. So I'm kinda lost as to what fscan is really doing I guess.
Here is the entire game:
Write a program that prints the temperature closest to 0 among input data. If two numbers are equally close to zero, positive integer has to be considered closest to zero (for instance, if the temperatures are -5 and 5, then display 5).
Your program must read the data from the standard input and write the result on the standard output.
Line 1: N, the number of temperatures to analyze
Line 2: The N temperatures expressed as integers ranging from -273 to 5526
Display 0 (zero) if no temperatures are provided. Otherwise, display the temperature closest to 0.