{"id":116,"date":"2008-07-04T23:11:49","date_gmt":"2008-07-04T17:41:49","guid":{"rendered":"http:\/\/www.bin-co.com\/blog\/?p=116"},"modified":"2008-07-04T23:11:49","modified_gmt":"2008-07-04T17:41:49","slug":"hello-script-for-c-language","status":"publish","type":"post","link":"https:\/\/www.bin-co.com\/blog\/2008\/07\/hello-script-for-c-language\/","title":{"rendered":"Hello Script for C Language"},"content":{"rendered":"<p class=\"intro\">C &#8211; the root of all modern language&#8217;s syntax. Here is the hello script for C. A &#8216;<a href=\"http:\/\/www.bin-co.com\/blog\/2008\/03\/learning-a-new-programming-language-the-hello-world-method\/\">Hello Script<\/a>&#8216; is a file that contains the most commonly used elements of a programming language so that it can be used as a cheat sheet when working with that language.<\/p>\n<blockquote>\n<p>C is a general-purpose, block structured, procedural, imperative computer programming language developed in 1972 by Dennis Ritchie. Although C was designed for implementing system software, it is also widely used for applications. It is widely used on a great many different software platforms and computer architectures, and several popular compilers exist.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/C_(programming_language)\">Wikipedia<\/a><\/p><\/blockquote>\n<p>Unfortunately, I am not an expert in C &#8211; I prefer dynamic languages over static ones. So if you find any problems in the script, please let me know in the comments.<\/p>\n<pre><code class=\"c\">\n#include &lt;stdio.h&gt;\n#include &lt;string.h&gt;\n\n\/\/ Function declaration\nvoid hello(char name[]) {\n \tchar result[50] = \"Hello, \";\n \tstrcat(result, name);\n \tprintf(\"%s\\n\", result);\n}\n\nint main() {\n\tint i;\n\t\/\/ Printing(IO)\n\tprintf(\"Hello World!\\n\");\n\t\n\t\/\/ Variables, concatenation\n\tchar name[] = \"Binny\";\n\tint year = 2008;\n\tprintf(\"Hello, %s - welcome to %d\\n\", name, year);\n\t\n\t\/\/If, else\n\tif (year &gt; 2008) {\n\t\tprintf(\"Welcome to the future - yes, we have flying cars!\");\n\t}\n\telse if(year &lt; 2008) {\n\t\tprintf(\"The past - please don't change anything. Don't step on any butterflies. And for the sake of all that's good and holy, stay away from your parents!\");\n\t}\n\telse {\n\t\tprintf(\"Anything wrong with your time machine? You have not gone anywhere, kiddo.\");\n\t}\n\tprintf(\"\\n\");\n\n\t\/\/ For loop\n\tfor(i=0; i&lt;3; i++) {\n\t\tprintf(\"%d) Hi there!\\n\", i);\n\t}\n\t\n \t\/\/Numerical Array, while\n \tchar rules[3][20]; \/\/I am sure there is a better way of doing this using poiters. If you know, please leave a few 'pointers' in the comment.\n \tstrcpy(rules[0], \"Do no harm\");\n \tstrcpy(rules[1], \"Obey\");\n \tstrcpy(rules[2], \"Continue Living\");\n \ti=0;\n\twhile(i&lt;3) {\n\t\tprintf(\"Rule %d : %s\\n\", i+1, rules[i]);\n\t\ti++;\n\t}\n\t\n\t\/\/ Struct - nearest thing C has to an associated array\n\tstruct structure {\n\t\tchar hello[20];\n\t\tint number;\n\t\tchar foo[20];\n\t} associated, new_associated;\n\tstrcpy(associated.hello, \"world\");\n\tassociated.number = 1337;\n\tstrcpy(associated.foo, \"bar\");\n\tprintf(\"hello: %s\\n\", associated.hello);\n\tprintf(\"number: %d\\n\", associated.number);\n\tprintf(\"foo: %s\\n\", associated.foo);\n\n\t\/\/ Function calling\n\thello(\"John Oldman\");\n\n\t\/\/ Writing to a file\n \tFILE *out;\n \tout = fop<!-- fix wordpress bug -->en(\"\/tmp\/Hello.txt\", \"w\");\n \tchar *str = \"Hello From C\";\n \tfputs(str, out);\n \tfclose(out);\n\t\n\t\/\/ Reading and displaying a file.\n\tFILE *in;\n\tin = fop<!-- fix wordpress bug -->en(\"Hello.c\", \"r\");\n\tif (in) {\n\t\twhile (!feof(in))\n\t\t\tprintf(\"%c\",fgetc(in));\n\t}\n\tfclose(in);\n\n\t\/\/ Run a system command.\n\tsys<!-- fix wordpress bug -->tem(\"ls\");\n\n\treturn 1;\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>C &#8211; the root of all modern language&#8217;s syntax. Here is the hello script for C. A &#8216;Hello Script&#8216; is a file that contains the <a class=\"mh-excerpt-more\" href=\"https:\/\/www.bin-co.com\/blog\/2008\/07\/hello-script-for-c-language\/\" title=\"Hello Script for C Language\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,28,29],"tags":[70,137,162,244,289],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-scripts","category-tutorial","category-web20","tag-c","tag-hello","tag-language","tag-scirpt","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":0,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bin-co.com\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}