We need to understand a little bit about how MS-DOS works to understand what is happening here. When data is read from the keyboard, under MS-DOS control, the characters are stored in a buffer until a carriage return is entered, at which time the entire string of characters is given to the program. While the characters are being typed, however, the characters are displayed one at a time on the monitor. This is called echo, and happens in many of the applications you run.
With the above paragraph in mind, it should be clear that when you are typing a line of data into SIMPLEIO", the characters are being echoed by MS-DOS, and when you return the carriage, the characters are given to the program. As each character is given to the program, it displays it on the screen resulting in a repeat of the line typed in. To better illustrate this, type a line with a capital X somewhere in the middle of the line. You can type as many characters as you like following the "X" and they will all display because the characters are being read in under MS-DOS, echoed to the monitor, and placed in the MS-DOS keyboard input buffer. MS-DOS doesn’t think there is anything special about a capital X. When the string is given to the program, however, the characters are accepted by the program one at a time and sent to the monitor one at a time, until a capitalXis encountered.
After the capitalXis displayed, the loop is terminated, and the program is terminated. The characters on the input line following the capital X are not displayed because the capital X signalled program termination. In the Applix 1616, the stdio.h function getchar() is defined in stdio.h as getch(), which is provided by 1616/OS, but is not exactly identical to the expected reslts from "getchar()". The keyboard buffer is read by getch() and the characters passed straight along to the program. Within the program, the characters are echoed to the display by putchar(), and the 1616/OS only has to change the cursor position. If you leave out the #include "stdi.h", then the HiTech C compiler will use its default "getchar()" function, which is correct, and will work the same as MS-DOS Compileand run"simpleio.c. After running the programseveral times andfeeling confidant that you understand the above explanation, we will go on to another program. Don’t get discouraged by the above seemingly weird behaviour of the I/O system. It is strange, but there are other ways to get data into the computer. You will actually find the above method
useful for many applications, and you will probably find some of the following useful also.
With the above paragraph in mind, it should be clear that when you are typing a line of data into SIMPLEIO", the characters are being echoed by MS-DOS, and when you return the carriage, the characters are given to the program. As each character is given to the program, it displays it on the screen resulting in a repeat of the line typed in. To better illustrate this, type a line with a capital X somewhere in the middle of the line. You can type as many characters as you like following the "X" and they will all display because the characters are being read in under MS-DOS, echoed to the monitor, and placed in the MS-DOS keyboard input buffer. MS-DOS doesn’t think there is anything special about a capital X. When the string is given to the program, however, the characters are accepted by the program one at a time and sent to the monitor one at a time, until a capitalXis encountered.
After the capitalXis displayed, the loop is terminated, and the program is terminated. The characters on the input line following the capital X are not displayed because the capital X signalled program termination. In the Applix 1616, the stdio.h function getchar() is defined in stdio.h as getch(), which is provided by 1616/OS, but is not exactly identical to the expected reslts from "getchar()". The keyboard buffer is read by getch() and the characters passed straight along to the program. Within the program, the characters are echoed to the display by putchar(), and the 1616/OS only has to change the cursor position. If you leave out the #include "stdi.h", then the HiTech C compiler will use its default "getchar()" function, which is correct, and will work the same as MS-DOS Compileand run"simpleio.c. After running the programseveral times andfeeling confidant that you understand the above explanation, we will go on to another program. Don’t get discouraged by the above seemingly weird behaviour of the I/O system. It is strange, but there are other ways to get data into the computer. You will actually find the above method
useful for many applications, and you will probably find some of the following useful also.