summaryrefslogtreecommitdiff
path: root/659/CH12/EX12.5
diff options
context:
space:
mode:
authorpriyanka2015-06-24 15:03:17 +0530
committerpriyanka2015-06-24 15:03:17 +0530
commitb1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b (patch)
treeab291cffc65280e58ac82470ba63fbcca7805165 /659/CH12/EX12.5
downloadScilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.gz
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.tar.bz2
Scilab-TBC-Uploads-b1f5c3f8d6671b4331cef1dcebdf63b7a43a3a2b.zip
initial commit / add all books
Diffstat (limited to '659/CH12/EX12.5')
-rwxr-xr-x659/CH12/EX12.5/exm12_5.sce31
-rwxr-xr-x659/CH12/EX12.5/exm12_5_output.PNGbin0 -> 13751 bytes
2 files changed, 31 insertions, 0 deletions
diff --git a/659/CH12/EX12.5/exm12_5.sce b/659/CH12/EX12.5/exm12_5.sce
new file mode 100755
index 000000000..0f8b82e2a
--- /dev/null
+++ b/659/CH12/EX12.5/exm12_5.sce
@@ -0,0 +1,31 @@
+// Example12.5
+//Write a program that uses function ftell(mtell) and fseek(mseek).
+
+warning('off');
+//Open file 'RANDOM' in write mode,fp is file descriptor
+fp=mopen('RANDOM','w');
+c=read(%io(1),1,1,'(a)');
+mfprintf(fp,'%s',c); //write data to the file
+printf("Number of characters entered = %d\n",mtell(fp));
+mclose(fp);
+
+//Open file 'RANDOM' in read mode
+fp=mopen('RANDOM','r');
+n=0;
+while(meof(fp)==0)
+//n is the offset from origin in number of bytes.
+//The new position is at the signed distance given by n bytes from the beginning
+ mseek(n,fp,'set');
+ //Print the chracter and its postion
+ printf("Position of %c is %d\n",ascii(mget(1,'c',fp)),mtell(fp));
+ n=n+5;
+end
+n=0; //Initial offset
+while(mtell(fp)>1)
+ //New position is at the signed distance given by n bytes from the end
+ mseek(n,fp,'end');
+ //Print the characters from the end
+ printf("%c",(ascii(mget(1,'c',fp))));
+ n=n-1;
+end
+mclose(fp);
diff --git a/659/CH12/EX12.5/exm12_5_output.PNG b/659/CH12/EX12.5/exm12_5_output.PNG
new file mode 100755
index 000000000..bb468ccca
--- /dev/null
+++ b/659/CH12/EX12.5/exm12_5_output.PNG
Binary files differ