title: Odd results following code in Head First C
body: <p>I'm doing the exercises in a book, <a href="http://oreilly.com/catalog/errata.csp?isbn=0636920015482" rel="nofollow noreferrer">Head First C</a>. I double-checked that my code is the same as in the book and I'm carefully following the steps in the book. </p>
  
  <p>The C file is supposed to take gps data and format it in JSON style. </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  
      float latitude;
      float longitude;
      char info[40];
      int started = 0;
  
      puts("data=[");
      while (scanf("%f, %f, %39[^\n]", &amp;latitude, &amp;longitude, info) ==3) {
        if (started) 
          printf(", \n");
  
        else 
          started = 1;
  
            printf("{latitude: %f, longitude: %f, info: '%s'}", latitude, longitude, info);
      }
      puts("\n]");
      return 0;
  }
  </code></pre>
  
  <p>First the book had us type in the data, to show us how tedious and poorly formatted it looks, then we learn to redirect stdin to read a file of comma-separated data, like so:</p>
  
  <pre><code>$ ./geo2json &lt; gpsdata.csv
  </code></pre>
  
  <p>I couldn't find source files online so I copy/pasted from the pdf of the book to create the csv file. </p>
  
  <pre><code>gpsdata.csv and gpsdata.txt
  
  42.363400,-71.098465,Speed = 21 
  42.363327,-71.097588,Speed = 23
  42.363255,-71.096710,Speed = 17
  42.363182,-71.095833,Speed = 22
  42.363110,-71.094955,Speed = 14
  42.363037,-71.094078,Speed = 16
  42.362965,-71.093201,Speed = 18
  42.362892,-71.092323,Speed = 22
  42.362820,-71.091446,Speed = 17
  42.362747,-71.090569,Speed = 23
  42.362675,-71.089691,Speed = 14
  42.362602,-71.088814,Speed = 19
  42.362530,-71.087936,Speed = 16
  42.362457,-71.087059,Speed = 16
  42.362385,-71.086182,Speed = 21
  </code></pre>
  
  <p>Weird stuff happened, so I went thru the lines and deleted then re-entered the line breaks in case there was some hidden formatting. I tried changing the file type from .csv to .txt. Neither made a difference. When I typed in the data, this weirdness did not happen.</p>
  
  <p>How it's supposed to look:</p>
  
  <p><img src="https://i.stack.imgur.com/RP9xP.jpg" alt="formatted data from the book"></p>
  
  <p>How it actually looks. Note how the last line is different. BTW sometimes the 'l' in latitude shows up on that last line. </p>
  
  <pre><code>login:~/programming/cfiles&gt; ./geo2json &lt; gpsdata.csv
  data=[
  '}, itude: 42.363400, longitude: -71.098465, info: 'Speed = 21
  '}, itude: 42.363327, longitude: -71.097588, info: 'Speed = 23
  '}, itude: 42.363255, longitude: -71.096710, info: 'Speed = 17
  '}, itude: 42.363182, longitude: -71.095833, info: 'Speed = 22
  '}, itude: 42.363110, longitude: -71.094955, info: 'Speed = 14
  '}, itude: 42.363037, longitude: -71.094078, info: 'Speed = 16
  '}, itude: 42.362965, longitude: -71.093201, info: 'Speed = 18
  '}, itude: 42.362892, longitude: -71.092323, info: 'Speed = 22
  '}, itude: 42.362820, longitude: -71.091446, info: 'Speed = 17
  '}, itude: 42.362747, longitude: -71.090569, info: 'Speed = 23
  '}, itude: 42.362675, longitude: -71.089691, info: 'Speed = 14
  '}, itude: 42.362602, longitude: -71.088814, info: 'Speed = 19
  '}, itude: 42.362530, longitude: -71.087936, info: 'Speed = 16
  '}, itude: 42.362457, longitude: -71.087059, info: 'Speed = 16
  '}atitude: 42.362385, longitude: -71.086182, info: 'Speed = 21
  ]
  </code></pre>
  
  <p>I checked the online errata and didn't see anything about this. I was using Cygwin but then tried linux, both had the same result.</p>
  
  <p>Any help or insight would be appreciated!</p>