home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / ctutor1.zip / CHAP09.TXT < prev    next >
Text File  |  1989-11-10  |  29KB  |  648 lines

  1.  
  2.  
  3.  
  4.  
  5.                                                     Chapter 9
  6.                                         STANDARD INPUT/OUTPUT
  7.  
  8.  
  9. THE STDIO.H HEADER FILE
  10. ____________________________________________________________
  11.  
  12. Load the file SIMPLEIO.C for our first look    ==============
  13. at a file with standard I/O.  Standard I/O       SIMPLEIO.C
  14. refers to the most usual places where data is  ==============
  15. either read from, the keyboard, or written
  16. to, the video monitor.  Since they are used
  17. so much, they are used as the default I/O devices and do not
  18. need to be named in the Input/Output instructions.  This will
  19. make more sense when we actually start to use them so lets
  20. look at the file in front of you.
  21.  
  22. The first thing you should take notice of is the second line
  23. of the file, the line with #include "stdio.h".  This is very
  24. much like the #define we have already studied, except that
  25. instead of a simple substitution, an entire file is read in
  26. at this point.  The system will find the file named STDIO.H
  27. and read its entire contents in, replacing this statement. 
  28. Obviously then, the file named STDIO.H must contain valid C
  29. source statements that can be compiled as part of a program. 
  30. This particular file is composed of several standard #defines
  31. to define some of the standard I/O operations.  The file is
  32. called a header file and you will find several different
  33. header files on the source disks that came with your C
  34. compiler.  Each of the header files has a specific purpose and
  35. any or all of them can be included in any program.
  36.  
  37. Your C compiler uses the double quote marks to indicate that
  38. the search for the include file will begin in the current
  39. directory, and if it not found there, the search will continue
  40. in the include directory as set up in the environment.  It
  41. also uses the "less than" and "greater than" signs to indicate
  42. that the file search should begin in the directory specified
  43. in the environment.  Most of the programs in this tutorial
  44. have the double quotes in the include statements.  The next
  45. program uses the "<" and ">" to illustrate the usage.  Note
  46. that this will result is a slightly faster (but probably
  47. unnoticeable) compilation because the system will not bother
  48. to search the current directory first.
  49.  
  50.  
  51. INPUT/OUTPUT OPERATIONS IN C
  52. ____________________________________________________________
  53.  
  54. Actually the C programming language has no input or output
  55. operations defined as part of the language, they must be user
  56. defined.  Since everybody does not want to reinvent his own
  57. input and output operations, the compiler writers have done
  58.  
  59.                                                      Page 9-1
  60.  
  61.                             Chapter 9 - Standard Input/Output
  62.  
  63. a lot of this for us and supplied us with several input
  64. functions and several output functions to aid in our program
  65. development.  The functions have become a standard, and you
  66. will find the same functions available in nearly every
  67. compiler.  In fact, the industry standard of the C language
  68. definition has become the book written by Kernigan and
  69. Ritchie, and they have included these functions in their
  70. definition.  You will often, when reading literature about C,
  71. find an author refer to K & R.  This refers to the book, "The
  72. C Programming Language", written by Kernigan and Ritchie.  You
  73. would be advised to purchase a copy for reference.  As of this
  74. writing, a second edition of this book is available and is the
  75. preferred edition.
  76.  
  77. You should print out the file named STDIO.H and spend some
  78. time studying it.  There will be a lot that you will not
  79. understand about it, but parts of it will look familiar.  The
  80. name STDIO.H is sort of cryptic for "standard input/output
  81. header", because that is exactly what it is.  It defines the
  82. standard input and output functions in the form of #defines
  83. and macros.  Don't worry too much about the details of this
  84. now.  You can always return to this topic later for more study
  85. if it interests you, but you will really have no need to
  86. completely understand the STDIO.H file.  You will have a
  87. tremendous need to use it however, so these comments on its
  88. use and purpose are necessary.
  89.  
  90.  
  91. OTHER INCLUDE FILES
  92. ____________________________________________________________
  93.  
  94. When you begin writing larger programs and splitting them up
  95. into separately compiled portions, you will have occasion to
  96. use some statements common to each of the portions.  It would
  97. be to your advantage to make a separate file containing the
  98. statements and use the #include to insert it into each of the
  99. files.  If you want to change any of the common statements,
  100. you will only need to change one file and you will be assured
  101. of having all of the common statements agree.  This is getting
  102. a little ahead of ourselves but you now have an idea how the
  103. #include directive can be used.
  104.  
  105.  
  106. BACK TO THE FILE NAMED SIMPLEIO.C
  107. ____________________________________________________________
  108.  
  109. Lets continue our tour of the file in question.  The one
  110. variable named c is defined and a message is printed out with
  111. the familiar printf() function.  We then find ourselves in a
  112. continuous loop as long as the value of c is not equal to
  113. capital X.  If there is any question in your mind about the
  114. loop control, you should review chapter 3 before continuing. 
  115. The two new functions within the loop are of paramount
  116. interest in this program since they are the new functions.
  117.  
  118.                                                      Page 9-2
  119.  
  120.                             Chapter 9 - Standard Input/Output
  121.  
  122. These are functions to read a character from the keyboard and
  123. display it on the monitor one character at a time.
  124.  
  125. The function getchar() reads a single character from the
  126. standard input device, the keyboard being assumed because that
  127. is the standard input device, and assigns it to the variable
  128. named c.  The next function putchar(), uses the standard
  129. output device, the video monitor, and outputs the character
  130. contained in the variable named c.  The character is output
  131. at the current cursor location and the cursor is advanced one
  132. space for the next character.  The system is therefore taking
  133. care of a lot of the overhead for us.  The loop continues
  134. reading and displaying characters until we type a capital X
  135. which terminates the loop. 
  136.  
  137. Compile and run this program for a few surprises.  When you
  138. type on the keyboard, you will notice that what you type is
  139. displayed faithfully on the screen, and when you hit the
  140. return key, the entire line is repeated.  We only told it to
  141. output each character once but it seems to be saving the
  142. characters up and redisplaying them.  A short explanation is
  143. in order.
  144.  
  145.  
  146. DOS IS HELPING US OUT
  147. ____________________________________________________________
  148.  
  149. We need to understand a little bit about how DOS works to
  150. understand what is happening here.  When data is read from the
  151. keyboard, under DOS control, the characters are stored in a
  152. buffer until a carriage return is entered at which time the
  153. entire string of characters is given to the program.  When the
  154. characters are being typed, however, the characters are
  155. displayed one at a time on the monitor.  This is called echo,
  156. and happens in many of the applications you run. 
  157.  
  158. With the above paragraph in mind, it should be clear that when
  159. you are typing a line of data into SIMPLEIO, the characters
  160. are being echoed by DOS, and when you return the carriage by
  161. hitting return or enter, the characters are given to the
  162. program.  As each character is given to the program, it
  163. displays it on the screen resulting in a repeat of the line
  164. typed in.  To better illustrate this, type a line with a
  165. capital X somewhere in the middle of the line.  You can type
  166. as many characters as you like following the X and they will
  167. all display because the characters are being read in under
  168. DOS, echoed to the monitor, and placed in the DOS input
  169. buffer.  DOS doesn't think there is anything special about a
  170. capital X.  When the string is given to the program, however,
  171. the characters are accepted by the program one at a time and
  172. sent to the monitor one at a time, until a capital X is
  173. encountered.  After the capital X is displayed, the loop is
  174. terminated, and the program is terminated.  The characters on
  175. the input line following the capital X are not displayed
  176.  
  177.                                                      Page 9-3
  178.  
  179.                             Chapter 9 - Standard Input/Output
  180.  
  181. because the capital X signalled program termination.  Compile
  182. and run SIMPLEIO.C.  After running the program several times
  183. and feeling confident that you understand the above
  184. explanation, we will go on to another program.
  185.  
  186. Don't get discouraged by the above seemingly weird behavior
  187. of the I/O system.  It is strange, but there are other ways
  188. to get data into the computer.  You will actually find the
  189. above method useful for many applications, and you will
  190. probably find some of the following useful also.
  191.  
  192.  
  193. ANOTHER STRANGE I/O METHOD
  194. ____________________________________________________________
  195.  
  196. Load the file named SINGLEIO.C and display it  ==============
  197. on your monitor for another method of            SINGLEIO.C
  198. character I/O.  Once again, we start with the  ==============
  199. standard I/O header file using the "<" and
  200. ">" method of defining it.  Then we define a
  201. variable named c, and finally we print a welcoming message. 
  202. Like the last program, we are in a loop that will continue to
  203. execute until we type a capital X, but the action is a little
  204. different here.
  205.  
  206. The function named getch() is a get character function.  It
  207. differs from the function named getchar() in that it does not
  208. get tied up in DOS.  It reads the character in without echo,
  209. and puts it directly into the program where it is operated on
  210. immediately.  This function therefore reads a character,
  211. immediately displays it on the screen, and continues the
  212. operation until a capital X is typed.  Note that although
  213. getch() is available with most popular microcomputer C
  214. compilers, it is not included in the ANSI standard and may not
  215. be available with all C compilers.  It's use may therefore
  216. make a program nonportable.
  217.  
  218. When you compile and run this program, you will find that
  219. there is no repeat of the lines when you hit a carriage
  220. return, and when you hit the capital X, the program terminates
  221. immediately.  No carriage return is needed to get it to accept
  222. the line with the X in it.  We do have another problem here,
  223. however, there is no linefeed with the carriage return.
  224.  
  225.  
  226. NOW WE NEED A LINE FEED
  227. ____________________________________________________________
  228.  
  229. It is not apparent to you in most application  ==============
  230. programs but when you hit the enter key, the     BETTERIN.C
  231. program supplies a linefeed to go with the     ==============
  232. carriage return.  You need to return to the
  233. left side of the monitor and you also need to
  234. drop down a line.  The linefeed is not automatic. We need to
  235.  
  236.                                                      Page 9-4
  237.  
  238.                             Chapter 9 - Standard Input/Output
  239.  
  240. improve our program to do this also.  If you will load and
  241. display the program named BETTERIN.C, you will find a change
  242. to incorporate this feature.
  243.  
  244. In BETTERIN.C, we have two additional statements at the
  245. beginning that will define the character codes for the
  246. linefeed (LF), and the carriage return (CR).  If you look at
  247. any ASCII table you will find that the codes 10 and 13 are
  248. exactly as defined here.  In the main program, after
  249. outputting the character in line 15, we compare it to CR, and
  250. if it is equal to CR, we also output a linefeed which is the
  251. LF.  We could have completely omitted the two #define
  252. statements and used the statement if (c == 13) putchar(10);
  253. but it would not be very descriptive of what we are doing
  254. here.  The method used in the program represents better
  255. programming practice.
  256.  
  257. Compile and run BETTERIN.C to see if it does what we have said
  258. it should do.  It should display exactly what you type in,
  259. including a linefeed with each carriage return, and should
  260. stop immediately when you type a capital X. 
  261.  
  262.  
  263. WHICH METHOD IS BEST?
  264. ____________________________________________________________
  265.  
  266. We have examined two methods of reading characters into a C
  267. program, and are faced with a choice of which one we should
  268. use.  It really depends on the application because each method
  269. has advantages and disadvantages. 
  270.  
  271. When using the first method, DOS is actually doing all of the
  272. work for us by storing the characters in an input buffer and
  273. signalling us when a full line has been entered.  We could
  274. write a program that, for example, did a lot of calculations,
  275. then went to get some input.  While we were doing the
  276. calculations, DOS would be accumulating a line of characters
  277. for us, and they would be there when we were ready for them. 
  278. However, we could not read in single keystrokes because DOS
  279. would not report a buffer of characters to us until it
  280. recognized a carriage return.
  281.  
  282. The second method, used in BETTERIN.C, allows us to get a
  283. single character, and act on it immediately.  We do not have
  284. to wait until DOS decides we can have a line of characters. 
  285. We cannot do anything else while we are waiting for a
  286. character because we are waiting for the input keystroke and
  287. tying up the entire machine.  This method is useful for highly
  288. interactive types of program interfaces.  It is up to you as
  289. the programmer to decide which is best for your needs.
  290.  
  291. I should mention at this point that there is also an ungetch()
  292. function that works with the getch() function.  If you getch
  293. a character and find that you have gone one too far, you can
  294.  
  295.                                                      Page 9-5
  296.  
  297.                             Chapter 9 - Standard Input/Output
  298.  
  299. ungetch it back to the input device.  This simplifies some
  300. programs because you don't know that you don't want the
  301. character until you get it.  You can only ungetch() one
  302. character back to the input device, but that is sufficient to
  303. accomplish the task this function was designed for.  It is
  304. difficult to demonstrate this function in a simple program so
  305. its use will be up to you to study when you need it.  Another
  306. function that may be available with your compiler, but is not
  307. part of the ANSI standard, is the getche() function which is
  308. identical to the getch() function except that it echoes the
  309. character to the monitor for you.
  310.  
  311. The discussion so far in this chapter, should be a good
  312. indication that, while the C programming language is very
  313. flexible, it does put a lot of responsibility on you as the
  314. programmer to keep many details in mind.
  315.  
  316.  
  317. NOW TO READ IN SOME INTEGERS
  318. ____________________________________________________________
  319.  
  320. Load and display the file named INTIN.C for     =============
  321. an example of reading in some formatted data.      INTIN.C
  322. The structure of this program is very similar   =============
  323. to the last three except that we define an
  324. int type variable and loop until the variable
  325. somehow acquires the value of 100.
  326.  
  327. Instead of reading in a character at a time, as we have in the
  328. last three example programs, we read in an entire integer
  329. value with one call using the function named scanf().  This
  330. function is very similar to the printf() that you have been
  331. using for quite some time by now except that it is used for
  332. input instead of output.  Examine the line with the scanf()
  333. and you will notice that it does not ask for the variable
  334. valin directly, but gives the address of the variable since
  335. it expects to have a value returned from the function.  Recall
  336. that a function must have the address of a variable in order
  337. to return a value to that variable in the calling program. 
  338. Failing to supply a pointer in the scanf() function is the
  339. most common problem encountered in using this function. 
  340.  
  341. The function scanf() scans the input line until it finds the
  342. first data field.  It ignores leading blanks and in this case,
  343. it reads integer characters until it finds a blank or an
  344. invalid decimal character, at which time it stops reading and
  345. returns the value. 
  346.  
  347. Remembering our discussion above about the way the DOS input
  348. buffer works, it should be clear that nothing is actually
  349. acted on until a complete line is entered and it is terminated
  350. by a carriage return.  At this time, the buffer is input, and
  351. our program will search across the line reading all integer
  352. values it can find until the line is completely scanned.  This
  353.  
  354.                                                      Page 9-6
  355.  
  356.                             Chapter 9 - Standard Input/Output
  357.  
  358. is because we are in a loop and we tell it to find a value,
  359. print it, find another, print it, etc.  If you enter several
  360. values on one line, it will read each one in succession and
  361. display the values.  Entering the value of 100 will cause the
  362. program to terminate, and entering the value 100 with other
  363. values following, will cause termination before the following
  364. values are considered. 
  365.  
  366.  
  367.  
  368. IT MAKES WRONG ANSWERS SOMETIMES
  369. ____________________________________________________________
  370.  
  371. If you enter a number up to and including 32767, it will
  372. display correctly, but if you enter a larger number, it will
  373. appear to make an error unless your system uses a much larger
  374. range for an int type variable.  For example, if you enter the
  375. value 32768, it will display the value of -32768, entering the
  376. value 65536 will display as a zero.  These are not errors but
  377. are caused by the way an integer is defined.  The most
  378. significant bit of the 16 bit pattern available for the
  379. integer variable is the sign bit, so there are only 15 bits
  380. left for the value.  The variable can therefore only have the
  381. values from -32768 to 32767, any other values are outside the
  382. range of integer variables.  This is up to you to take care
  383. of in your programs.  It is another example of the increased
  384. responsibility you must assume using C rather than another
  385. high level language such as Pascal, Modula-2, etc.
  386.  
  387. The above paragraph is true for most MS-DOS C compilers. 
  388. There is a very small possibility that your compiler uses an
  389. integer value stored in a field size other than 16 bits.  If
  390. that is the case, the same principles will be true but with
  391. different limits than those given above.
  392.  
  393. Compile and run this program, entering several numbers on a
  394. line to see the results, and with varying numbers of blanks
  395. between the numbers.  Try entering numbers that are too big
  396. to see what happens, and finally enter some invalid characters
  397. to see what the system does with nondecimal characters.
  398.  
  399.  
  400.  
  401. CHARACTER STRING INPUT
  402. ____________________________________________________________
  403.  
  404. Load and display the file named STRINGIN.C     ==============
  405. for an example of reading a string variable.     STRINGIN.C
  406. This program is identical to the last one      ==============
  407. except that instead of an integer variable,
  408. we have defined a string variable with an
  409. upper limit of 24 characters (remember that a string variable
  410. must have a null character at the end).  The variable in the
  411. scanf() does not need an & because big is an array variable
  412.  
  413.                                                      Page 9-7
  414.  
  415.                             Chapter 9 - Standard Input/Output
  416.  
  417. and by definition it is already a pointer.  This program
  418. should require no additional explanation.  Compile and run it
  419. to see if it works the way you expect.
  420.  
  421. You probably got a surprise when you ran it because it
  422. separated your sentence into separate words.  When used in the
  423. string mode of input, scanf() reads characters into the string
  424. until it comes to either the end of a line or a blank
  425. character.  Therefore, it reads a word, finds the blank
  426. following it, and displays the result.  Since we are in a
  427. loop, this program continues to read words until it exhausts
  428. the DOS input buffer.  We have written this program to stop
  429. whenever it finds a capital X in column 1, but since the
  430. sentence is split up into individual words, it will stop
  431. anytime a word begins with capital X.  Try entering a 5 word
  432. sentence with a capital X as the first character in the third
  433. word.  You should get the first three words displayed, and the
  434. last two simply ignored when the program stops.
  435.  
  436. Try entering more than 24 characters to see what the program
  437. does.  In an actual program, it is your responsibility to
  438. count characters and stop when the input buffer is full.  You
  439. may be getting the feeling that a lot of responsibility is
  440. placed on you when writing in C.  It is, but you also get a
  441. lot of flexibility in the bargain too.
  442.  
  443.  
  444.  
  445. INPUT/OUTPUT PROGRAMMING IN C
  446. ____________________________________________________________
  447.  
  448. C was not designed to be used as a language for lots of input
  449. and output, but as a systems language where a lot of internal
  450. operations are required.  You would do well to use another
  451. language for I/O intensive programming, but C could be used
  452. if you desire.  The keyboard input is very flexible, allowing
  453. you to get at the data in a very low level way, but very
  454. little help is given you.  It is therefore up to you to take
  455. care of all of the bookkeeping chores associated with your
  456. required I/O operations.  This may seem like a real pain in
  457. the neck, but in any given program, you only need to define
  458. your input routines once and then use them as needed.  Don't
  459. let this worry you.  As you gain experience with C, you will
  460. easily handle your I/O requirements.
  461.  
  462. One final point must be made about these I/O functions.  It
  463. is perfectly permissible to intermix scanf() and getchar()
  464. functions during read operations.  In the same manner, it is
  465. also fine to intermix the output functions, printf() and
  466. putchar(). 
  467.  
  468.  
  469.  
  470.  
  471.  
  472.                                                      Page 9-8
  473.  
  474.                             Chapter 9 - Standard Input/Output
  475.  
  476. IN MEMORY I/O
  477. ____________________________________________________________
  478.  
  479. The next operation may seem a little strange    =============
  480. at first, but you will probably see lots of        INMEM.C
  481. uses for it as you gain experience.  Load the   =============
  482. file named INMEM.C and display it for another
  483. type of I/O, one that never accesses the
  484. outside world, but stays in the computer.
  485.  
  486. In INMEM.C, we define a few variables, then assign some values
  487. to the ones named numbers for illustrative purposes and then
  488. use an sprintf() function.  The function acts just like a
  489. normal printf() function except that instead of printing the
  490. line of output to a device, it prints the line of formatted
  491. output to a character string in memory.  In this case the
  492. string goes to the string variable named line, because that
  493. is the string name we inserted as the first argument in the
  494. sprintf() function.  The spaces after the 2nd %d were put
  495. there to illustrate that the next function will search
  496. properly across the line.  We print the resulting string and
  497. find that the output is identical to what it would have been
  498. by using a printf() instead of the sprintf() in the first
  499. place.  You will see that when you compile and run the program
  500. shortly.
  501.  
  502. Since the generated string is still in memory, we can now read
  503. it with the function sscanf().  We tell the function in its
  504. first argument that line is the string to use for its input,
  505. and the remaining parts of the line are exactly what we would
  506. use if we were going to use the scanf() function and read data
  507. from outside the computer.  Note that it is essential that we
  508. use pointers to the data because we want to return data from
  509. a function.  Just to illustrate that there are many ways to
  510. declare a pointer several methods are used, but all are
  511. pointers.  The first two simply declare the address of the
  512. elements of the array, while the last three use the fact that
  513. result, without the accompanying subscript, is a pointer. 
  514. Just to keep it interesting, the values are read back in
  515. reverse order.  Finally the values are displayed on the
  516. monitor. 
  517.  
  518.  
  519. IS THAT REALLY USEFUL?
  520. ____________________________________________________________
  521.  
  522. It seems sort of silly to read input data from within the
  523. computer but it does have a real purpose.  It is possible to
  524. read data from an input device using any of the standard
  525. functions and then do a format conversion in memory.  You
  526. could read in a line of data, look at a few significant
  527. characters, then use these formatted input routines to reduce
  528. the line of data to internal representation.  That would sure
  529. beat writing your own data formatting routines.
  530.  
  531.                                                      Page 9-9
  532.  
  533.                             Chapter 9 - Standard Input/Output
  534.  
  535.  
  536. STANDARD ERROR OUTPUT
  537. ____________________________________________________________
  538.  
  539. Sometimes it is desirable to redirect the       =============
  540. output from the standard output device to a       SPECIAL.C
  541. file.  However, you may still want the error    =============
  542. messages to go to the standard output device,
  543. in our case the monitor.  This next function
  544. allows you to do that.  Load and display SPECIAL.C for an
  545. example of this new function.
  546.  
  547. The program consists of a loop with two messages output, one
  548. to the standard output device and the other to the standard
  549. error device.  The message to the standard error device is
  550. output with the function fprintf() and includes the device
  551. name stderr as the first argument.  Other than those two small
  552. changes, it is the same as our standard printf function.  (You
  553. will see more of the fprintf() function in the next chapter,
  554. but its operation fit in better as a part of this chapter.) 
  555. Ignore the line with the exit for the moment, we will return
  556. to it.
  557.  
  558. Compile and run this program, and you will find 12 lines of
  559. output on the monitor.  To see the difference, run the program
  560. again with redirected output to a file named STUFF by entering
  561. the following line at the DOS prompt;
  562.  
  563.      A> special >stuff
  564.  
  565. This time you will only get the 6 lines output to the standard
  566. error device, and if you look in your directory, you will find
  567. the file named STUFF containing the other 6 lines, those to
  568. the standard output device.  You can use I/O redirection with
  569. any of the programs we have run so far, and as you may guess,
  570. you can also read from a file using I/O redirection but we
  571. will study a better way to read from a file in the next
  572. chapter.  More information about I/O redirection can be found
  573. in your DOS manual.  
  574.  
  575.  
  576.  
  577. WHAT ABOUT THE exit(4) STATEMENT?
  578. ____________________________________________________________
  579.  
  580. Now to keep our promise about the exit(4) statement. Redisplay
  581. the file named SPECIAL.C on your monitor.  The last statement
  582. simply exits the program and returns the value of 4 to DOS. 
  583. Any number from 0 to 9 can be used in the parentheses for DOS
  584. communication.  If you are operating in a BATCH file, this
  585. number can be tested with the ERRORLEVEL command.
  586.  
  587. Most compilers that operate in several passes return a 1 with
  588. this mechanism to indicate that a fatal error has been
  589.  
  590.                                                     Page 9-10
  591.  
  592.                             Chapter 9 - Standard Input/Output
  593.  
  594. detected and it would be a waste of time to go on to another
  595. pass resulting in even more errors.
  596.  
  597. It is therefore wise to use a batch file for compiling
  598. programs and testing the returned value for errors.  A check
  599. of the documentation for my Compaq, resulted in a minimal and
  600. confusing documentation of the ERRORLEVEL command, so a brief
  601. description of it is given in this file in case your
  602. documentation does not include enough information to allow you
  603. to use it.
  604.  
  605. One additional feature must be mentioned here.  Since we wish
  606. to return an int value to the operating system, we must define
  607. the main program entry point as returning an int rather than
  608. a void as we have used in most of the example programs to this
  609. point.  Refer to line 5 for an example of this extension.
  610.  
  611.  
  612. PROGRAMMING EXERCISE
  613. ____________________________________________________________
  614.  
  615. 1.   Write a program to read in a character using a loop, and
  616.      display the character in its normal char form.  Also
  617.      display it as a decimal number. Check for a dollar sign
  618.      to use as the stop character.  Use the getch() form of
  619.      input so it will print immediately.  Hit some of the
  620.      special keys, such as function keys, when you run the
  621.      program for some surprises. You will get two inputs from
  622.      the special keys, the first being a zero which is the
  623.      indication to the system that a special key was hit.
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.                                                     Page 9-11
  648.