summaryrefslogtreecommitdiff
path: root/A_First_course_in_Programming_with_C/Chapter13.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'A_First_course_in_Programming_with_C/Chapter13.ipynb')
-rwxr-xr-xA_First_course_in_Programming_with_C/Chapter13.ipynb169
1 files changed, 169 insertions, 0 deletions
diff --git a/A_First_course_in_Programming_with_C/Chapter13.ipynb b/A_First_course_in_Programming_with_C/Chapter13.ipynb
new file mode 100755
index 00000000..84f2242b
--- /dev/null
+++ b/A_First_course_in_Programming_with_C/Chapter13.ipynb
@@ -0,0 +1,169 @@
+{
+ "metadata": {
+ "name": ""
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: C Preprocessor and Command Line Arguments"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 1, Page Number : PCL-3"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "def BIG(a,b):\n",
+ " if a > b:\n",
+ " return a\n",
+ " else:\n",
+ " return b\n",
+ " \n",
+ "def WAITMSG():\n",
+ " return \"\\nPress any key to continue...\"\n",
+ " \n",
+ "x = int(raw_input(\"\\nEnter two integers : \"))\n",
+ "y = int(raw_input(\"\"))\n",
+ "\n",
+ "print \"\\nBiggest integer is \",BIG(x,y),WAITMSG()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Enter two integers : 5\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "8\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Biggest integer is 8 \n",
+ "Press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 2, Page Number : PCL-6"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import time\n",
+ "\n",
+ "argv1 = \"SAMPLE.TXT\"\n",
+ "argv2 = \"SAMPLE.BAK\"\n",
+ "\n",
+ "source_fptr = open(\"SAMPLE.TXT\",\"r\")\n",
+ "target_fptr = open(\"SAMPLE.BAK\",\"w+\")\n",
+ "\n",
+ "if source_fptr == 0:\n",
+ " print \"\\nNo content/source file!!!\"\n",
+ " print \"\\n press any key to continue...\"\n",
+ "else:\n",
+ " print \"\\nCopying source file \",argv1,\" to target file \",argv2\n",
+ " print \"\\n please wait.\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ " print \".\"\n",
+ "\n",
+ " if target_fptr == 0:\n",
+ " print \"\\nNo content/target file!!!\"\n",
+ " print \"\\n\\n Press any key to continue...\"\n",
+ " else:\n",
+ " while True:\n",
+ " ch = source_fptr.read(1)\n",
+ " if not ch:\n",
+ " break\n",
+ " target_fptr.write(\"%c\"%(ch))\n",
+ " print \"\\n\\nCopy completed, the target file contents\"\n",
+ " print \"\\n----------------------------------------\\n\"\n",
+ " target_fptr.close()\n",
+ " target_fptr = open(\"SAMPLE.BAK\",\"r\")\n",
+ " ch = target_fptr.readlines()\n",
+ " for line in ch:\n",
+ " print line\n",
+ " source_fptr.close()\n",
+ " target_fptr.close()\n",
+ " print \"\\n\\n press any key to continue...\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ "Copying source file SAMPLE.TXT to target file SAMPLE.BAK\n",
+ "\n",
+ " please wait.\n",
+ ".\n",
+ ".\n",
+ ".\n",
+ ".\n",
+ "\n",
+ "\n",
+ "Copy completed, the target file contents\n",
+ "\n",
+ "----------------------------------------\n",
+ "\n",
+ "Computer Programming in C language is widely used for Science and Engineering applications.\n",
+ "\n",
+ "\n",
+ " press any key to continue...\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file