diff options
Diffstat (limited to 'ANSI_C_Programming_by_Yashwant_Kanetkar/chapter13.ipynb')
-rwxr-xr-x | ANSI_C_Programming_by_Yashwant_Kanetkar/chapter13.ipynb | 711 |
1 files changed, 711 insertions, 0 deletions
diff --git a/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter13.ipynb b/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter13.ipynb new file mode 100755 index 00000000..b37b75e4 --- /dev/null +++ b/ANSI_C_Programming_by_Yashwant_Kanetkar/chapter13.ipynb @@ -0,0 +1,711 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:af78c3ae74c9d65bb5213be5077524875e7de56ebf2616c80d19baf13507c5b4" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "CHAPTER 13: MORE ISSUES IN INPUT/OUTPUT" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:434-435" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import sys\n", + "if(len(sys.argv)!=3):\n", + " print \"Improper number of arguments\\n\"\n", + " sys.exit(0)\n", + "try:\n", + " fs=open(sys.argv[1], \"r\")\n", + "except:\n", + " sys.exit(\"Cannot open source file\\n\")\n", + "try:\n", + " ft=open(sys.argv[2], \"w\")\n", + "except:\n", + " fs.close()\n", + " sys.exit(\"Cannot open source file\\n\")\n", + "ch=fs.readlines()\n", + "ft.writelines(ch)\n", + "fs.close()\n", + "ft.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:437-438" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "try:\n", + " fp=open('python.txt','w')\n", + " while True:\n", + " ch=fp.read(1)\n", + " if not ch:\n", + " break;\n", + " print \"%c\" % (ch)\n", + "except:\n", + " print \"Error in reading file\\n\" " + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Error in reading file\n", + "\n" + ] + } + ], + "prompt_number": 15 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:439" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import tempfile\n", + "import win32api\n", + "import win32print\n", + "import sys\n", + "\n", + "try:\n", + " fp=open('poem.txt','r') #No need to open it\n", + "except:\n", + " sys.exit(\"Cannot open file\\n\")\n", + "win32api.ShellExecute (\n", + " 0,\n", + " \"print\",\n", + " \"poem.txt\",\n", + " '/d:\"%s\"' % win32print.GetDefaultPrinter (),\n", + " \".\",\n", + " 0\n", + ")\n", + "fp.close()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "metadata": {}, + "output_type": "pyout", + "prompt_number": 3, + "text": [ + "42" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:440-441" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "import sys\n", + "ch = sys.stdin.read(1)\n", + "while (len(ch)>0):\n", + " sys.stdout.write(ch)\n", + " ch = sys.stdin.read(1)" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 11 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "EXAMPLE ON PAGE:442" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + " \n", + "for ch in range(0,256,1):\n", + " print \"%d %c\\n\" % (ch,ch)" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "0 \u0000\n", + "\n", + "1 \u0001\n", + "\n", + "2 \u0002\n", + "\n", + "3 \u0003\n", + "\n", + "4 \u0004\n", + "\n", + "5 \u0005\n", + "\n", + "6 \u0006\n", + "\n", + "7 \u0007\n", + "\n", + "8 \b\n", + "\n", + "9 \t\n", + "\n", + "10 \n", + "\n", + "\n", + "11 \u000b", + "\n", + "\n", + "12 \f", + "\n", + "\n", + "13 \r\n", + "\n", + "14 \u000e\n", + "\n", + "15 \u000f\n", + "\n", + "16 \u0010\n", + "\n", + "17 \u0011\n", + "\n", + "18 \u0012\n", + "\n", + "19 \u0013\n", + "\n", + "20 \u0014\n", + "\n", + "21 \u0015\n", + "\n", + "22 \u0016\n", + "\n", + "23 \u0017\n", + "\n", + "24 \u0018\n", + "\n", + "25 \u0019\n", + "\n", + "26 \u001a\n", + "\n", + "27 \u001b\n", + "\n", + "28 \u001c", + "\n", + "\n", + "29 \u001d", + "\n", + "\n", + "30 \u001e", + "\n", + "\n", + "31 \u001f\n", + "\n", + "32 \n", + "\n", + "33 !\n", + "\n", + "34 \"\n", + "\n", + "35 #\n", + "\n", + "36 $\n", + "\n", + "37 %\n", + "\n", + "38 &\n", + "\n", + "39 '\n", + "\n", + "40 (\n", + "\n", + "41 )\n", + "\n", + "42 *\n", + "\n", + "43 +\n", + "\n", + "44 ,\n", + "\n", + "45 -\n", + "\n", + "46 .\n", + "\n", + "47 /\n", + "\n", + "48 0\n", + "\n", + "49 1\n", + "\n", + "50 2\n", + "\n", + "51 3\n", + "\n", + "52 4\n", + "\n", + "53 5\n", + "\n", + "54 6\n", + "\n", + "55 7\n", + "\n", + "56 8\n", + "\n", + "57 9\n", + "\n", + "58 :\n", + "\n", + "59 ;\n", + "\n", + "60 <\n", + "\n", + "61 =\n", + "\n", + "62 >\n", + "\n", + "63 ?\n", + "\n", + "64 @\n", + "\n", + "65 A\n", + "\n", + "66 B\n", + "\n", + "67 C\n", + "\n", + "68 D\n", + "\n", + "69 E\n", + "\n", + "70 F\n", + "\n", + "71 G\n", + "\n", + "72 H\n", + "\n", + "73 I\n", + "\n", + "74 J\n", + "\n", + "75 K\n", + "\n", + "76 L\n", + "\n", + "77 M\n", + "\n", + "78 N\n", + "\n", + "79 O\n", + "\n", + "80 P\n", + "\n", + "81 Q\n", + "\n", + "82 R\n", + "\n", + "83 S\n", + "\n", + "84 T\n", + "\n", + "85 U\n", + "\n", + "86 V\n", + "\n", + "87 W\n", + "\n", + "88 X\n", + "\n", + "89 Y\n", + "\n", + "90 Z\n", + "\n", + "91 [\n", + "\n", + "92 \\\n", + "\n", + "93 ]\n", + "\n", + "94 ^\n", + "\n", + "95 _\n", + "\n", + "96 `\n", + "\n", + "97 a\n", + "\n", + "98 b\n", + "\n", + "99 c\n", + "\n", + "100 d\n", + "\n", + "101 e\n", + "\n", + "102 f\n", + "\n", + "103 g\n", + "\n", + "104 h\n", + "\n", + "105 i\n", + "\n", + "106 j\n", + "\n", + "107 k\n", + "\n", + "108 l\n", + "\n", + "109 m\n", + "\n", + "110 n\n", + "\n", + "111 o\n", + "\n", + "112 p\n", + "\n", + "113 q\n", + "\n", + "114 r\n", + "\n", + "115 s\n", + "\n", + "116 t\n", + "\n", + "117 u\n", + "\n", + "118 v\n", + "\n", + "119 w\n", + "\n", + "120 x\n", + "\n", + "121 y\n", + "\n", + "122 z\n", + "\n", + "123 {\n", + "\n", + "124 |\n", + "\n", + "125 }\n", + "\n", + "126 ~\n", + "\n", + "127 \u007f\n", + "\n", + "128 \ufffd\n", + "\n", + "129 \ufffd\n", + "\n", + "130 \ufffd\n", + "\n", + "131 \ufffd\n", + "\n", + "132 \ufffd\n", + "\n", + "133 \ufffd\n", + "\n", + "134 \ufffd\n", + "\n", + "135 \ufffd\n", + "\n", + "136 \ufffd\n", + "\n", + "137 \ufffd\n", + "\n", + "138 \ufffd\n", + "\n", + "139 \ufffd\n", + "\n", + "140 \ufffd\n", + "\n", + "141 \ufffd\n", + "\n", + "142 \ufffd\n", + "\n", + "143 \ufffd\n", + "\n", + "144 \ufffd\n", + "\n", + "145 \ufffd\n", + "\n", + "146 \ufffd\n", + "\n", + "147 \ufffd\n", + "\n", + "148 \ufffd\n", + "\n", + "149 \ufffd\n", + "\n", + "150 \ufffd\n", + "\n", + "151 \ufffd\n", + "\n", + "152 \ufffd\n", + "\n", + "153 \ufffd\n", + "\n", + "154 \ufffd\n", + "\n", + "155 \ufffd\n", + "\n", + "156 \ufffd\n", + "\n", + "157 \ufffd\n", + "\n", + "158 \ufffd\n", + "\n", + "159 \ufffd\n", + "\n", + "160 \ufffd\n", + "\n", + "161 \ufffd\n", + "\n", + "162 \ufffd\n", + "\n", + "163 \ufffd\n", + "\n", + "164 \ufffd\n", + "\n", + "165 \ufffd\n", + "\n", + "166 \ufffd\n", + "\n", + "167 \ufffd\n", + "\n", + "168 \ufffd\n", + "\n", + "169 \ufffd\n", + "\n", + "170 \ufffd\n", + "\n", + "171 \ufffd\n", + "\n", + "172 \ufffd\n", + "\n", + "173 \ufffd\n", + "\n", + "174 \ufffd\n", + "\n", + "175 \ufffd\n", + "\n", + "176 \ufffd\n", + "\n", + "177 \ufffd\n", + "\n", + "178 \ufffd\n", + "\n", + "179 \ufffd\n", + "\n", + "180 \ufffd\n", + "\n", + "181 \ufffd\n", + "\n", + "182 \ufffd\n", + "\n", + "183 \ufffd\n", + "\n", + "184 \ufffd\n", + "\n", + "185 \ufffd\n", + "\n", + "186 \ufffd\n", + "\n", + "187 \ufffd\n", + "\n", + "188 \ufffd\n", + "\n", + "189 \ufffd\n", + "\n", + "190 \ufffd\n", + "\n", + "191 \ufffd\n", + "\n", + "192 \ufffd\n", + "\n", + "193 \ufffd\n", + "\n", + "194 \ufffd\n", + "\n", + "195 \ufffd\n", + "\n", + "196 \ufffd\n", + "\n", + "197 \ufffd\n", + "\n", + "198 \ufffd\n", + "\n", + "199 \ufffd\n", + "\n", + "200 \ufffd\n", + "\n", + "201 \ufffd\n", + "\n", + "202 \ufffd\n", + "\n", + "203 \ufffd\n", + "\n", + "204 \ufffd\n", + "\n", + "205 \ufffd\n", + "\n", + "206 \ufffd\n", + "\n", + "207 \ufffd\n", + "\n", + "208 \ufffd\n", + "\n", + "209 \ufffd\n", + "\n", + "210 \ufffd\n", + "\n", + "211 \ufffd\n", + "\n", + "212 \ufffd\n", + "\n", + "213 \ufffd\n", + "\n", + "214 \ufffd\n", + "\n", + "215 \ufffd\n", + "\n", + "216 \ufffd\n", + "\n", + "217 \ufffd\n", + "\n", + "218 \ufffd\n", + "\n", + "219 \ufffd\n", + "\n", + "220 \ufffd\n", + "\n", + "221 \ufffd\n", + "\n", + "222 \ufffd\n", + "\n", + "223 \ufffd\n", + "\n", + "224 \ufffd\n", + "\n", + "225 \ufffd\n", + "\n", + "226 \ufffd\n", + "\n", + "227 \ufffd\n", + "\n", + "228 \ufffd\n", + "\n", + "229 \ufffd\n", + "\n", + "230 \ufffd\n", + "\n", + "231 \ufffd\n", + "\n", + "232 \ufffd\n", + "\n", + "233 \ufffd\n", + "\n", + "234 \ufffd\n", + "\n", + "235 \ufffd\n", + "\n", + "236 \ufffd\n", + "\n", + "237 \ufffd\n", + "\n", + "238 \ufffd\n", + "\n", + "239 \ufffd\n", + "\n", + "240 \ufffd\n", + "\n", + "241 \ufffd\n", + "\n", + "242 \ufffd\n", + "\n", + "243 \ufffd\n", + "\n", + "244 \ufffd\n", + "\n", + "245 \ufffd\n", + "\n", + "246 \ufffd\n", + "\n", + "247 \ufffd\n", + "\n", + "248 \ufffd\n", + "\n", + "249 \ufffd\n", + "\n", + "250 \ufffd\n", + "\n", + "251 \ufffd\n", + "\n", + "252 \ufffd\n", + "\n", + "253 \ufffd\n", + "\n", + "254 \ufffd\n", + "\n", + "255 \ufffd\n", + "\n" + ] + } + ], + "prompt_number": 1 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |