# There is no concept of pointer and dynamic memory allocation in pyton so i have done in this manner
def StrCopy(str1,str2):
str1=list(str1)
str2=list(str2)
for i in range(len(str1)):
str2[i]=str1[i]
str2[i]='\0'
str1="Use malloc() to allocate memory"
ptr_str=str
ptr_str= str1
if(ptr_str!= None):
StrCopy(str1,ptr_str)
print "The string pointed to by ptr_str is : %s" % ptr_str
else:
print "malloc() function failed."
# There is no concept of pointer and dynamic memory allocation in pyton so i have done in this manner
def DataMultiply(max1,ptr_int):
for i in range(max1):
for j in range(max1):
ptr_int=(i+1)*(j+1)
return ptr_int
def TablePrint(max1,ptr_int):
print "The Multiplication table of %d is:" % max1
print ""
for i in range(max1):
print "%4d" % (i+1),
print ""
for i in range(max1):
print "----",
print""
for i in range(max1):
print "%d|" % (i+1),
for j in range(max1):
print "%3d" % ptr_int,
print""
ptr_int=int
ptr_int=0
key='c'
max1=0
termination=0
while(key != 'x'):
max1=int(raw_input("Enter a single digit number: "))
if(ptr_int != None):
print ptr_int
ptr_int=DataMultiply(max1,ptr_int)
print ptr_int
TablePrint(max1,ptr_int)
else:
print "Malloc() function failed."
termination=1
key='x'
key=raw_input("\n\nPress x key to quit; other key to continue.")
print"\nBYE\n"
# There is no concept of pointer and dynamic memory allocation in pyton so i have done in this manner
ptr1=float
ptr2=float
ptr1=0.0
ptr2=0.0
termination=1
n=5
if(ptr1 == None):
print "Malloc() failed."
elif(ptr2 == None):
print "Calloc() failed."
else:
for i in range(n):
print "ptr1[%d]= %5.2f, ptr2[%d]= %5.2f" %(i,(ptr1+i),i,(ptr2+i))
termination=0
# There is no concept of pointer and dynamic memory allocation in pyton so i have done in this manner
def StrCopy(str1,str2):
str1=list(str1)
str2=list(str1)
for i in range(len(str1)-1):
str2[i]=str1[i]
str2[i]='\0'
return str2
str1=["There's music in the sighing of a reed;","There's music in the gushing of a rill;","There's music in all things if men had ears;","There earth is but an echo of the spheres.\n"]
termination=0
if(ptr == None):
print "Malloc() failed."
termination=1
else:
ptr1=StrCopy(str1[0],ptr)
print "".join(ptr1)
for i in range(1,4):
if (ptr == None):
print "realloc() failed."
termination=1
i=4
else:
ptr1=StrCopy(str1[i],ptr)
print "".join(ptr1)