National Instruments 320682C Musical Toy Instrument User Manual


 
Chapter 2 Formatting and I/O Library
© National Instruments Corporation 2-71 LabWindows/CVI Standard Libraries
writing beyond the end of filename. Notice that the width specified is one less than the size
of filename. This allows room for the ASCII NUL that ScanIn appends at the end of
filename. The q modifier causes ScanIn to fill any unused bytes at the end of filename
with ASCII NULs. Without the q modifier, all unused bytes are filled with spaces, except for the
ASCII NUL at the end.
The call to ScanIn in this example skips over leading spaces and tabs and terminates the string
on an embedded space. For other options, see the String to String example earlier in this section.
Reading a Line from the Standard Input
char buf[81];
nbytes = ReadLine (0, buf, 80);
Remarks
The previous two examples show how to read single items from the keyboard. When you are
prompted to enter several items on one line, it is often easier to read the entire line into a buffer
before parsing it. This can be done via the Formatting and I/O Library function ReadLine.
The first parameter to ReadLine is a file handle. In this case, the file handle is zero, which is
the handle reserved for the Standard Input. The other two parameters are a buffer and the
maximum number of bytes to place in the buffer. ReadLine always appends an ASCII NUL at
the end of the bytes read. Thus, the maximum number of bytes passed to ReadLine must be at
least one less than the size of the buffer.
ReadLine transfers every character from the input line to the buffer, including leading,
embedded, and trailing spaces, until the maximum number of bytes (for example, 80) have been
transferred. Any remaining characters at the end of the line are discarded. The linefeed is never
transferred to the buffer.
ReadLine returns the number of bytes read, including the number discarded, but excluding the
linefeed.