summaryrefslogtreecommitdiff
path: root/1088/CH23/EX23.6/Result6.txt
diff options
context:
space:
mode:
Diffstat (limited to '1088/CH23/EX23.6/Result6.txt')
-rwxr-xr-x1088/CH23/EX23.6/Result6.txt176
1 files changed, 176 insertions, 0 deletions
diff --git a/1088/CH23/EX23.6/Result6.txt b/1088/CH23/EX23.6/Result6.txt
new file mode 100755
index 000000000..841add07e
--- /dev/null
+++ b/1088/CH23/EX23.6/Result6.txt
@@ -0,0 +1,176 @@
+ ans =
+
+ 1.
+
+-->exec('Example6.sci')
+
+-->clear
+
+-->flag=1
+ flag =
+
+ 1.
+
+-->mode(-1)
+Current date is 23-Jun-2013
+
+Welcome to the Textbook Companionship Project 2013
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Book Title : UNIX CONCEPTS AND APPLICATIONS
+
+ Book Edition : 4
+
+ Book Author : Sumitabha Das
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Code Author : Pranav Bhat T
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+
+ Chapter Number : 23
+
+ Chapter Title : Systems programming I- Files
++-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+Example 6 : Show the method of reversing a file using error handling alternatives
+
+ ****************************************************************
+
+ Answer :
+
+ INSTRUCTIONS :
+
+ 1.These programs are part of systems programming in Unix and the commands have NO EQUIVALENT IN SCILAB
+
+ 2.However if possible some selected programmes have been TRIED TO BE IMPLEMENTED
+
+ 3.For most of the programmes whose equivalent is NOT THERE IN SCILAB,only the output has been printed as given in the textbook w
+ ith no interactive input as in the programme below
+
+ 4.However the .c files which are displayed here are also made into a seperate file.If you are a unix user then try compiling and
+ running the programme with gcc or cc compiler
+
+ 5.The inconvenience is regretted.
+.............Press [ENTER] to continue..... UNIX SHELL SIMULATOR(DEMO VERSION WITH PRELOADED COMMANDS)
+
+
+
+
+$ cat reverse_read2.c # to open the file emp.lst /* Program: reverse_read2.c -- Reads a file in reverse - uses error handling */
+
+#include <fcntl.h> /* For 0_RDONLY */
+#include <unistd.h> /* For STDOUT_FILENO */
+#include <errno.h> /* For ENOENT, errno, etc. */
+#include <stdio.h> /* For ENOENT, errno, etc. */
+
+int main(int argc, chr **argv) {
+ int size, fd;
+ char buf; /* Single-character buffer */
+ char *mesg = "Not enough arguments\n" ;
+
+ if (argc != 2) { /* Our own user-defined error message */
+ write(STDERR_FILENO, mesg, strlen(mesg)); /* Crude form of error*/
+ exit(1); /*handling using write*/
+ } /* Use fprintf instead*/
+
+ if ((fd = open(argv[1],O_RDONLY)) == -1) {
+ if (errno == ENOENT) { /* Checking for specific error*/
+ fprintf(stderr, "%s\n",stderror(errno)); /*perror is better*/
+ exit(2);
+ } else {
+ perror(argv[1]); /* Using two library functions */
+ exit(3); /* perror and exit.often the */
+ } /* preferred way */
+ }
+
+ lseek(fd, 1, SEEK_END); /* Pointer taken to EOF + 1 first */
+ while (lseek(fd, -2, SEEK_CUR) >=0) { /* and then back by two bytes */
+ if (read(fd, &buf, 1) != 1) { /* A signal can create error here */
+ perror("read");
+ exit(4);
+ }
+ if (write(STDOUT_FILENO, &buf, 1) != 1) { /* Disk may run out of space */
+ perror("write");
+ exit(5);
+ }
+ }
+ close(fd); /*Can have error here too*/
+ exit(0); /* exit doesn't return - hence no error */
+}
+
+$ ls
+ ans =
+
+!vv.txt !
+! !
+!reverse_read2.c !
+! !
+!Result6.txt !
+! !
+!Example9.sci !
+! !
+!Example8.sci !
+! !
+!Example7.sci !
+! !
+!Example6.sci !
+! !
+!Example2.sci !
+! !
+!Example13.sci !
+! !
+!Example12.sci !
+! !
+!Example11.sci !
+! !
+!Example10.sci !
+! !
+!ex9 !
+! !
+!ex8 !
+! !
+!ex7 !
+! !
+!ex6 !
+! !
+!ex5 !
+! !
+!ex4 !
+! !
+!ex3 !
+! !
+!ex2 !
+! !
+!ex13 !
+! !
+!ex12 !
+! !
+!ex11 !
+! !
+!ex10 !
+! !
+!ex1 !
+
+$ cat vv.txt hi there
+How are you
+I am fine
+Thank You
+Good Bye
+$ cc reverse_read2.c$ a.out vv.txt
+......a blank line... The terminating \n of the last lineeyB dooG
+
+uoY knahT
+
+ enif ma I
+
+uoy era woH
+
+ereht ih
+
+
+$ exit #To exit the current simulation terminal and return to Scilab console
+
+........# (hit [ENTER] for result)
+
+ BACK TO SCILAB CONSOLE...
+Loading initial environment
+-->diary(0)