{"id":2315,"date":"2017-02-01T00:01:16","date_gmt":"2017-02-01T08:01:16","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=2315"},"modified":"2022-02-17T07:38:34","modified_gmt":"2022-02-17T15:38:34","slug":"the-csv-file","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=2315","title":{"rendered":"The CSV File"},"content":{"rendered":"<p>Of all the common file formats, the CSV is probably the oldest one still in use. It&#8217;s a plain text file, so the formatted data appears is readable by humans: Each line is a record. Each field is separated by a single comma.<br \/>\n<!--more--><br \/>\nOther plain text file formats are popular today, including XML and JSON, but CSV is easy to read and write in C without having to use external libraries.<\/p>\n<p>Right-click <a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/02\/weather_data.csv\">this link<\/a> to download a typical CSV file. This one stores dates and temperatures from this year&#8217;s brutal winter in my home town. The data is formatted as follows:<\/p>\n<pre><code>(<em>int<\/em>)year, (<em>int<\/em>)month, (<em>int<\/em>)day, (<em>float<\/em>)high, (<em>float<\/em>)low<\/code><\/pre>\n<p>When you know what the fields represent, the CSV file makes sense; otherwise it&#8217;s just a list of meaningless numbers. In this case, the format uses numeric values (no strings). Some values are integers, others real numbers (floats). Strings in a CSV file are usually enclosed in double quotes, though this practice isn&#8217;t consistent. Regardless, for this month&#8217;s Exercise, the data are all numbers.<\/p>\n<p>Your task is to create code that reads the CSV file, <code>weather_data.csv<\/code> (<a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2017\/02\/weather_data.csv\">link<\/a>). Each line is processed and presented in the following output format:<\/p>\n<pre><code>  December 25 2016:     High 29.0      Low 19.0<\/code><\/pre>\n<p>This task portends a more complex program that I offer as next month&#8217;s Exercise. Until then, on your own, write the code to process the CSV file.<\/p>\n<p>(<a href=\"http:\/\/c-for-dummies.com\/blog\/?p=2355\">Click here<\/a> to view my solution, but please try the exercise on your own before you see what I did.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write code that fetches data from this common, plain text, file format. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=2315\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-2315","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2315","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2315"}],"version-history":[{"count":11,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2315\/revisions"}],"predecessor-version":[{"id":5219,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/2315\/revisions\/5219"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}