Chapter 13: C Preprocessor and Command Line Arguments

Example 1, Page Number : PCL-3

In [3]:
def BIG(a,b):
    if a > b:
        return a
    else:
        return b
    
def WAITMSG():
    return "\nPress any key to continue..."
    
x = int(raw_input("\nEnter two integers : "))
y = int(raw_input(""))

print "\nBiggest integer is ",BIG(x,y),WAITMSG()
Enter two integers : 5
8

Biggest integer is  8 
Press any key to continue...

Example 2, Page Number : PCL-6

In [2]:
import time

argv1 = "SAMPLE.TXT"
argv2 = "SAMPLE.BAK"

source_fptr = open("SAMPLE.TXT","r")
target_fptr = open("SAMPLE.BAK","w+")

if source_fptr == 0:
    print "\nNo content/source file!!!"
    print "\n      press any key to continue..."
else:
    print "\nCopying source file ",argv1," to target file ",argv2
    print "\n  please wait."
    print "."
    print "."
    print "."
    print "."

    if target_fptr == 0:
        print "\nNo content/target file!!!"
        print "\n\n  Press any key to continue..."
    else:
        while True:
            ch = source_fptr.read(1)
            if not ch:
                break
            target_fptr.write("%c"%(ch))
        print "\n\nCopy completed, the target file contents"
        print "\n----------------------------------------\n"
        target_fptr.close()
        target_fptr = open("SAMPLE.BAK","r")
        ch = target_fptr.readlines()
        for line in ch:
            print line
        source_fptr.close()
        target_fptr.close()
        print "\n\n press any key to continue..."
Copying source file  SAMPLE.TXT  to target file  SAMPLE.BAK

  please wait.
.
.
.
.


Copy completed, the target file contents

----------------------------------------

Computer Programming in C language is widely used for Science and Engineering applications.


 press any key to continue...
In [ ]: