{"id":2009,"date":"2015-10-20T12:37:44","date_gmt":"2015-10-20T10:37:44","guid":{"rendered":"http:\/\/www.blue.pri.ee\/ttu\/?page_id=2009"},"modified":"2022-08-15T13:02:28","modified_gmt":"2022-08-15T11:02:28","slug":"characters-c","status":"publish","type":"page","link":"https:\/\/blue.pri.ee\/ttu\/programming-i\/samples\/characters-c\/","title":{"rendered":"Manipulating characters (characters.c)"},"content":{"rendered":"<pre class=\"lang:c decode:true \">\/**\r\n * Fail:        characters.c\r\n * Author:      Risto Heinsar\r\n * Created:     06.11.2014\r\n * Modified:    30.11.2021\r\n *\r\n * Description: The example shows that characters in C are nothing\r\n *              but just numbers from ASCII table and how they can be\r\n *              manipulated one character at a time.\r\n *\/\r\n\r\n#include &lt;stdio.h&gt;\r\n\r\nint main(void)\r\n{\r\n    char character1 = 'a';\r\n    char character2 = 65;\r\n    printf(\"Characters are just numbers based on ASCII table:\\n\");\r\n    printf(\"(%c %hhd)\\n\", character1, character1); \/\/ windowsis %hd\r\n\tprintf(\"(%c %hhd)\", character2, character2);\r\n\tprintf(\"\\n\\n\");\r\n\r\n    char character3 = character1 + 1;\r\n    printf(\"You can do basic math with characters: %c + 1 -&gt; %c\\n\\n\",\r\n           character1, character3);\r\n\r\n    char character4 = character1 - 32;\r\n    printf(\"Upper and lower case characters have an offset of 32. \"\r\n           \"Notice that it's only a single bit (2^5) \"\r\n           \"%c - 32 -&gt; %c\\n\\n\", character1, character4);\r\n\r\n    char word[] = \"cafe\";\r\n    word[2] = 'k';\r\n    printf(\"Text is just an array of characters that can be indexed\"\r\n           \" and manipulated one character at a time.\\n\"\r\n           \"The %s is a lie.\\n\\n\", word);\r\n\r\n    char string[] = \"Text manipulation\";\r\n    string[4] = '\\0';\r\n    printf(\"The end of the string is denoted by a zero-terminator. \"\r\n           \"Where-ever it is put, that's where the string is considered \"\r\n           \"to end. E.g. if i put it in the middle of a word: %s\\n\\n\", string);\r\n    printf(\"You don't also need to start printing from the beginning: %s\\n\",\r\n           &amp;string[5]);\r\n\r\n    printf(\"I can also print characters from a string: %c%c%c%c\\n\",\r\n           string[0], string[1], string[2], string[3]);\r\n\r\n    return 0;\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * Fail: characters.c * Author: Risto Heinsar * Created: 06.11.2014 * Modified: 30.11.2021 * * Description: The example shows that characters in C are nothing * but just numbers from ASCII table and how they can be * manipulated one character at a time. *\/ #include &lt;stdio.h&gt; int main(void) { char character1 = &#8216;a&#8217;; &hellip; <a href=\"https:\/\/blue.pri.ee\/ttu\/programming-i\/samples\/characters-c\/\" class=\"more-link\">Loe edasi <span class=\"screen-reader-text\">Manipulating characters (characters.c)<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1521,"menu_order":16,"comment_status":"closed","ping_status":"closed","template":"page-templates\/code-width.php","meta":{"footnotes":""},"class_list":["post-2009","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/2009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/comments?post=2009"}],"version-history":[{"count":0,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/2009\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/pages\/1521"}],"wp:attachment":[{"href":"https:\/\/blue.pri.ee\/ttu\/wp-json\/wp\/v2\/media?parent=2009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}