title: Read in Numbers from a File in C
body: <p>I have a file called <code>points.dat</code> which reads something like:<br>
  5<br>
  2 5<br>
  -1 18<br>
  0 6<br>
  1 -1<br>
  10 0  </p>
  
  <p>The first number is how many ordered pairs there are.  The next 5 lines contain those ordered pairs.  What can I do to read in the first number, determine how many points there are (from here I can <code>malloc</code> an array of <code>structs</code> to store the points in).</p>
  
  <p>My problem is that <code>fgetc</code> doesn't really do the job here.  What if the first number is two digits?  Say the first number is 10.  <code>fgetc</code> will only retrieve the '1'.  Also, <code>fgets</code> doesn't really work, since you need to supply it the length of the amount of characters you want to read in.  The same applies for <code>fscanf</code>.  </p>
  
  <p>The real trouble comes in when it's time to retrieve the ordered pairs.  I have no idea how to do this either.  My only thoughts so far is look at a line: if it sees non-spaces or non-'\n's, it will read in the number as the x coordinate of point 1.  Loop.  Get y coordinate.  Once it hits a '\n', it will now move on to the next line, and begin looking for values to store in the next <code>struct</code> in the array of <code>structs</code>.</p>
  
  <p>(While doing this, I also need to be sure <code>atoi</code> can convert all of these into integers... ).</p>
  
  <p>If anyone has any ideas to help, they are appreciated.</p>