{"id":6494,"date":"2024-08-01T00:01:39","date_gmt":"2024-08-01T07:01:39","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6494"},"modified":"2024-08-08T22:07:52","modified_gmt":"2024-08-09T05:07:52","slug":"the-seventh-line","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6494","title":{"rendered":"The Seventh Line"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9734; &#9734;<\/h2>\n<p>For me, the scariest part of learning how to program a computer was file access. The problem was the horrid documentation. It introduced both sequential and random file access together without much explanation. So it was with much trepidation that I wrote my first file I\/O program. That&#8217;s when I realized that the manual was stupid.<br \/>\n<!--more--><br \/>\nIn my books and online courses, I teach sequential file access first. I don&#8217;t even bother mentioning random access, as introducing the two together is what confused me way back when. With C, a file is read just like any other input. A text file is scooped up one line at a time, which leads to this month&#8217;s Exercise.<\/p>\n<p>Your task is to read the seventh line from a named file. Blank lines in the file count. If the file lacks a seventh line, report that it&#8217;s missing. Likewise, report when the line is blank or too large to be read.<\/p>\n<p>Here is output from my solution when ran on the file <a href=\"https:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2024\/08\/sonnet18.txt\" target=\"_new\" rel=\"noopener\"><code>sonnet18<\/code><\/a>:<\/p>\n<p><code>The seventh line of file 'sonnet18.txt' is:<br \/>\nAnd every fair from fair sometime declines,<\/code><\/p>\n<p>When run on a file without a seventh line, here is the output:<\/p>\n<p><code>File 'gettysburg.txt' lacks a seventh line<\/code><\/p>\n<p>Please try this exercise on your own before you check out <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6514\">my solution<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Test your file access skills. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6494\">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-6494","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\/6494","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=6494"}],"version-history":[{"count":6,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6494\/revisions"}],"predecessor-version":[{"id":6532,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6494\/revisions\/6532"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}