XML

kent logo

CO538 Anonymous Questions and Answers Keyword Index

This page provides a keyword index to questions and answers. Clicking on a keyword will take you to a page containing all questions and answers for that keyword, grouped by year.

To submit a question, use the anonymous questions page. You may find the keyword index and/or top-level index useful for locating past questions and answers.

Keyword reference for keyboard-input

2003

Question 64 (2003):

Am I correct in thinking the command line to run the program would be along the lines of (assuming `data.txt' is the data going in):

    data.txt | q6

?

Answer 64:

Not quite, see the answer to Question 52 (2000). What you probably meant for the above was:

    raptor$ cat data.txt | ./q6

Keywords: q6 , keyboard-input


Question 19 (2003):

Is there something special that we need to do to get what we press on our keyboards to register in occam as my program isn't picking up any keyboard inputs, yet by my reckoning it should be. It works for the `a3.occ' file tho ?

Help!

Answer 19:

If you have a correctly programmed monitor process, there should be no problem with the keyboard. When you type keys into occam programs, they are not echo'd back to the screen unless you explicitly program this -- so it appears you are typing blind. Might this be the problem ?

If things ought to be happening, but aren't, double-check the `monitor' programming. Also check that it is wired up correctly -- i.e. with the keyboard channel.

Keywords: keyboard-input , q4

2000

Question 52 (2000):

I assume that q6 is supposed to read the file (nn_small.txt etc.). I have answered the question, but it still takes input from the keyboard.

It will collate all of the marks typed in using the correct standard - but to display the results I cannot just type enter, I must type a non-numeric character twice (e.g. "f f") before the results will be displayed. I am hoping this is a problem that will be fixed by the reading of the file, but I can't be sure until I can read the file.

Also, the comments added to the code make it sound like the output should be placed in a file rather than on the screen. Is this the case (and have we covered how to do this?) or is printing the results to the screen acceptable?

Answer 52:

You do not have to do anything in your occam code for this question to take input from a file or output to a file.

Your occam executable, q6, is a Unix process (in the KRoC implementations for Solaris and Linux). A Unix process takes text input from its standard input device and produces text output on its standard output device. By default, these devices are, respectively, your terminal keyboard and screen.

However, Unix allows you to specify that standard input is to be taken from a file and/or that standard output should be written to a file. To do this, we use re-direction operators - for example:

  raptor$ q6 < nn_data.txt

will run your q6 process and take standard input from the file nn_data.txt. KRoC maps Unix standard input to the compulsory keyboard input channel (the first parameter to your PROC q6). The starter code given in q6.occ reads from that channel - so all is done.

If you want to save the output in a file, don't change your program - just run:

  raptor$ q6 < nn_data.txt > results.txt

KRoC maps Unix standard output to the compulsory screen output channel (the second parameter to your PROC q6). The above command redirects that standard output to the named file.

[Note: KRoC does, of course, have a full library for file handling - but this is not included in the course library (course.lib) and is not part of the examinable course. Anyone wanting to find out more, please mail me.]

Running q6 interactively is a bit painful! What you type is not being echoed to the screen - so you won't see it. To begin with, you will see the NAME/MARK table headings that are output during initialisation of the display process. But, then, you won't see anything until you have typed in all your test data and indicated its end. For data coming from a file, the end is simply the end-of-file. For data coming from the keyboard, you indicate the end by typing the ASCII end-of-transmission character - which is CTL-D. Note that this should be typed in a legal position - i.e. following a name and mark pair - and may need a further carriage-return character to get it delivered to your occam process.

The anonymous questioner found an alternative way to end the data, which was to type in illegal data (e.g. "f f") - a name followed by something other than a mark. If that happens, the read.data process is programmed to abandon processing input and issue the poison signal (i.e. just as if the end-of-transmission or end-of-file was reached). This is documented in the description of read.data in your q6.occ file.

Redirecting standard input/output is a standard Unix capability (that you should know).

Keywords: q6 , keyboard-input

Referrers: Question 64 (2003) , Question 55 (2000)

Valid CSS!

Valid XHTML 1.0!

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.
Last modified Mon May 20 13:50:27 2013
This document is maintained by Fred Barnes, to whom any comments and corrections should be addressed.