#Variable declaration
name= "Klinsman" # character array or string
i = 0
#while loop for printing
while i <= 7 :
print name[i]
i = i + 1
#Variable declaration
name= "Klinsman\0" # character array or string
i = 0
#while loop for printing
while (name[i] != '\0') :
print name[i]
i = i + 1
#Variable declaration
name = "Klinsman\0" # string or character array
i = 0
ptr = name[i] # store base address of string
#Result
while ptr != '\0':
print ptr
i = i+1
ptr = name[i]
#Variable declaration
arr = "Bamboozled" # character array or string
#string length function
len1 = len(arr)
len2 = len( "Humpty Dumpty" )
#Result
print "string = %s length = %d" %( arr, len1 )
print "string = %s length = %d" %("Humpty Dumpty", len2 )
#Function definition
def xstrlen(s):
length = 0
while ( s[length] != '\0' ):
length += 1
return length
#Variable declaration
arr = "Bamboozled\0" # character array or string
#Function calls
len1 = xstrlen(arr)
len2 = xstrlen( "Humpty Dumpty\0" )
#Result
print "string = %s length = %d" %( arr, len1 )
print "string = %s length = %d" %("Humpty Dumpty\0", len2 )
#Variable declaration
source = "Sayonara"
target = []
#strcpy function
import copy
target = copy.copy(source)
#Result
print "source string = ", source
print "target string = ", target
#Function definition
def xstrcpy (t,s):
i = 0
while ( s[i] != '\0' ):
t = t + s[i]
i = i + 1
return t
#Variable declaration
source = "Sayonara\0"
target = ''
target = xstrcpy ( target, source ) # function call
#Result
print "source string = ", source
print "target string = ", target
#Variable declaration
source = "Folks!"
target = "Hello"
target = target + source # string concatenation
#Result
print "source string = ", source
print "target string = ", target
#Variable declaration
string1 = "Jerry\0"
string2 = "Ferry\0"
#Function definition
def strcmp (string1 , string2):
if (string1 == string2):
v = 0 #If the two strings are identical, strcmp returns a value zero
return v
else:
n = 0
while ( string1[n]):
if ( string1[n] == string2[n]):
n = n + 1
continue
else:
v = ord(string1[n]) - ord(string2[n]) #returns the numeric difference between the ASCII values of the first non-matching pairs of characters
return v
return v
#Function call
i = strcmp ( string1, "Jerry\0" )
j = strcmp ( string1, string2 )
k = strcmp ( string1, "Jerry boy\0" )
#Result
print i,j,k
#Function definition
def strcmp (string1 , string2):
if (string1 == string2):
v = 0 #If the two strings are identical, strcmp returns a value zero
return v
else:
n = 0
while ( string1[n]):
if ( string1[n] == string2[n]):
n = n + 1
continue
else:
v = ord(string1[n]) - ord(string2[n]) #returns the numeric difference between the ASCII values of the first non-matching pairs of characters
return v
return v
#Variable declaration
FOUND = 1
NOTFOUND = 0
masterlist =["akshay","parag","raman","srinivas","gopal","rajesh"]
yourname = []
flag = NOTFOUND
#Input from user
#yourname = raw_input("Enter your name: ")
yourname = "Akshatha"
#Checking in the master list
for i in range(0,6):
a = strcmp ( masterlist[i], yourname )
if a == 0:
print "Welcome, you can enter the palace"
flag = FOUND
break
if flag == NOTFOUND :
print "Sorry, you are a trespasser"
#Variable declaration
names = ["akshay\0\0\0","parag\0\0\0\0","raman\0\0\0\0","srinivas\0","gopal\0\0\0\0","rajesh\0\0\0"]
#Initial condition
print "Original: ", names[2], names[3]
#Exchanging names
for i in range(0,9):
t = names[3][i]
names[3] = names[3][0:i] + names[2][i] + names[3][i+1:]
names[2] = names[2][0:i] + t + names[2][i+1:]
#Result
print "New: ", names[2], names[3]
#Variable declaration
names = ["akshay\0\0\0","parag\0\0\0\0","raman\0\0\0\0","srinivas\0","gopal\0\0\0\0","rajesh\0\0\0"]
#Initial condition
print "Original: ", names[2], names[3]
#Exchanging names
temp = names[2]
names[2] = names[3]
names[3] = temp
#Result
print "New: ", names[2], names[3]
import copy
#Variable declaration
names = []
n=["John","Max","Jim","Tony","Tom","Harry"]
for i in range(0,6):
n1 = n[i]
p = copy.copy(n1)
names.append(p)
for i in range(0,6):
print names[i]