{"id":154,"date":"2013-07-01T00:01:43","date_gmt":"2013-07-01T08:01:43","guid":{"rendered":"http:\/\/c-for-dummies.com\/blog\/?p=154"},"modified":"2013-06-29T06:48:36","modified_gmt":"2013-06-29T14:48:36","slug":"we-have-a-winnah","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=154","title":{"rendered":"We Have a Winnah!"},"content":{"rendered":"<p>The game of Tic-Tac-Toe is played on a simple 3-by-3 grid, what C programmers would call a matrix. It&#8217;s not <em>The Matrix<\/em>, of course, but it&#8217;s a simple array in which players can battle.<br \/>\n<!--more--><br \/>\nCoding a Tic-Tac-Toe game would involve multiple steps, such as creating the game matrix, accepting input to place an X or an O, plus a function to determine whether or not a winning move has been made. That last steps is this month&#8217;s exercise.<\/p>\n<p>Oh, no: I wouldn&#8217;t dare put a full-on Tic-Tac-Toe game as an exercise. It&#8217;s something you probably want to handle one step at a time. This exercise is an important step, but not the entire code.<\/p>\n<p>To prevent burnout, I&#8217;ve listed the bulk of the code below. The only thing missing is the <em>tictactoe()<\/em> function, which evaluates the matrix to determine whether a valid winning combination has occurred. Your task this month is to write that <em>tictactoe()<\/em> function.<\/p>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\nvoid showgrid(int *array);\r\nint tictactoe(int *array);\r\n\r\nint main()\r\n{\r\n    int sample1[] = { 0, 0, 1, 0, 1, 0, 1, 0, 0 };\r\n    int result;\r\n\r\n    showgrid(sample1);\r\n    result = tictactoe(sample1);\r\n    if(result)\r\n        puts(\"That's a winner!\");\r\n    else\r\n        puts(\"No winnger.\");\r\n\r\n    return(0);\r\n}\r\n\r\nvoid showgrid(int *array)\r\n{\r\n    int x;\r\n\r\n    puts(\"TIC-TAC-TOE:\");\r\n    for(x=0;x&lt;9;x+=3)\r\n    {\r\n        printf(\"%d %d %d\\n\",\r\n            array[x],\r\n            array[x+1],\r\n            array[x+2]);\r\n    }\r\n}\r\n\r\nint tictactoe(int *array)\r\n{\r\n}<\/pre>\n<p>Please give this one a shot before you click the link below to view my solution. Remember that my solution is merely one of many; it&#8217;s not the right solution, nor is it the perfect solution.<\/p>\n<p><a href=\"http:\/\/c-for-dummies.com\/blog\/wp-content\/uploads\/2013\/07\/07exercise.c\">Exercise Solution<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the most basic computer games is Tic-Tac-Toe. If you haven&#8217;t yet coded such a game, this month&#8217;s exercise may inspire you. <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=154\">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-154","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\/154","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=154"}],"version-history":[{"count":4,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":159,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions\/159"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}