{"id":17,"date":"2016-07-26T17:47:41","date_gmt":"2016-07-26T17:47:41","guid":{"rendered":"http:\/\/54.169.157.34\/blog\/?p=17"},"modified":"2016-07-27T06:35:49","modified_gmt":"2016-07-27T06:35:49","slug":"escape-sequences-and-formatted-io-functions","status":"publish","type":"post","link":"https:\/\/codeinsightacademy.com\/blog\/c-programming\/escape-sequences-and-formatted-io-functions\/","title":{"rendered":"Escape Sequences and Formatted I\/O Functions"},"content":{"rendered":"<p><strong>Escape sequences<\/strong><\/p>\n<p>The following escape sequences allow special characters to be put into the source code.<\/p>\n<table style=\"height: 940px;\" width=\"637\">\n<tbody>\n<tr>\n<td width=\"72\">Escape<br \/>\nSequence<\/td>\n<td width=\"104\">Name<\/td>\n<td width=\"371\">Meaning<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\a<\/td>\n<td width=\"104\">Alert<\/td>\n<td width=\"371\">Produces an audible or visible alert.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\b<\/td>\n<td width=\"104\">Backspace<\/td>\n<td width=\"371\">Moves the cursor back one position (non-destructive).<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\f<\/td>\n<td width=\"104\">Form Feed<\/td>\n<td width=\"371\">Moves the cursor to the first position of the next page.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\n<\/td>\n<td width=\"104\">New Line<\/td>\n<td width=\"371\">Moves the cursor to the first position of the next line.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\r<\/td>\n<td width=\"104\">Carriage Return<\/td>\n<td width=\"371\">Moves the cursor to the first position of the current line.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\t<\/td>\n<td width=\"104\">Horizontal Tab<\/td>\n<td width=\"371\">Moves the cursor to the next horizontal tabular position.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\v<\/td>\n<td width=\"104\">Vertial Tab<\/td>\n<td width=\"371\">Moves the cursor to the next vertical tabular position.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\&#8217;<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Produces a single quote.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\&#8221;<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Produces a double quote.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\?<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Produces a question mark.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\"><a href=\"\/\">\\\\<\/a><\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Produces a single backslash.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\0<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Produces a null character.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\ddd<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Defines one character by the octal digits (base-8 number)<\/td>\n<\/tr>\n<tr>\n<td width=\"72\">\\xdd<\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\">Defines one character by the hexadecimal digit.<\/td>\n<\/tr>\n<tr>\n<td width=\"72\"><\/td>\n<td width=\"104\"><\/td>\n<td width=\"371\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Examples:<\/p>\n<p>p rintf(\u201c\\12\u201d); &#8211; Produces the decimal character 10 (x0A Hex).<\/p>\n<p>printf(\u201c\\xFF\u201d); &#8211; Produces the decimal character \u2013 1 or 255<\/p>\n<p>printf(\u201c\\x123\u201d); &#8211; Produces a single character<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Formatted I\/O Functions<\/strong><\/p>\n<p>printf Functions<\/p>\n<p>int printf(const char * format,\u2026);<\/p>\n<p>int sprint(char *str, const char * format, \u2026);<\/p>\n<p>The printf functions provide a means to output formatted information to a stream.<\/p>\n<p>printf sends formatted output to stdout<\/p>\n<p>sprintf sends formatted output to a string<\/p>\n<p>These functions take the format string specified by the format argument and apply each following argument to the format specifiers in the string in a left to right fashion. Each character in the format string is copied to the stream except for conversion characters which specify a format specifier.<\/p>\n<p>&nbsp;<\/p>\n<p>A conversion specifier begins with the % character. After the % character come the following in this order:<\/p>\n<p><strong>[flags]<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Control the conversion (optional).<\/p>\n<p><strong>[width]<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Defines the number of characters to print (optional).<\/p>\n<p><strong>[.precision]<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Defines the amount of precision to print for a number type (optional).<\/p>\n<p><strong>[modifier]<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Overrides the size (type) of the argument (optional).<\/p>\n<p><strong>[type]<\/strong>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 The type of conversion to be applied (required).<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Width:<\/strong><\/p>\n<p>The width of the field is specified here with a decimal value. If the value is not large enough to fill the width, then the rest of the field is padded with spaces. If the value overflows the width of the field, then the field is expanded to fit the value.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Precision:<\/strong><\/p>\n<p>The precision begins with a dob (.) to distinguish itself from the width specifier. The precision can be given as a decimal value or as an asterisk (*). If a * is used, then the next argument (which is an int type) specifies the precision.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>scanf Functions<\/strong><\/p>\n<p>Declarations:<\/p>\n<p>int scanf(const char * format, \u2026);<\/p>\n<p>int sscanf(const char * str, const char * format, \u2026);<\/p>\n<p>The scanf functions provide a means to input formatted information from a stream.<\/p>\n<p>scanf reads formatted input from stdin<\/p>\n<p>sscanf reads formatted input from a string<\/p>\n<p>These functions take input in a manner that is specified by the format argument and store each input field into the following arguments in a left to right fashion. Each input field is specified in the format string with a conversion specifier which specifies how the input is to be stored in appropriate variable.<\/p>\n<p><strong>Char I\/O<\/strong><\/p>\n<p><strong>getchar <\/strong> : getchar reads a single character from standard input.<\/p>\n<p>Syntax : \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int getchar();<\/p>\n<p>It requires the user to press enter after entering character.<\/p>\n<p><strong>Putchar : <\/strong>putchar writes a single character to standard output.<\/p>\n<p>Syntax: \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int putchar(int value)<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Escape sequences The following escape sequences allow special characters to be put into the source code. Escape Sequence Name Meaning \\a Alert Produces an audible or visible alert. \\b Backspace Moves the cursor back one position (non-destructive). \\f Form Feed Moves the cursor to the first position of the next page. \\n New Line Moves [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/17"}],"collection":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":4,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":21,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/posts\/17\/revisions\/21"}],"wp:attachment":[{"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeinsightacademy.com\/blog\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}