\subsection{Terminal I/O}

\index{input/output}
\charmpp\ provides both C and \CC\ style methods of doing terminal I/O.  

In place of C-style printf and scanf, \charmpp\ provides
\kw{CkPrintf} and \kw{CkScanf}.  These functions have
interfaces that are identical to their C counterparts, but there are some
differences in their behavior that should be mentioned.

\function{int CkPrintf(format [, arg]*)} \index{CkPrintf} \index{input/output}
\desc{This call is used for atomic terminal output. Its usage is similar to
\texttt{printf} in C.  However, \kw{CkPrintf} has some special properties
that make it more suited for parallel programming on networks of
workstations.  \kw{CkPrintf} routes all terminal output to the \kw{charmrun},
which is running on the host computer.  So, if a
\index{chare}chare on processor 3 makes a call to \kw{CkPrintf}, that call
puts the output in a TCP message and sends it to host
computer where it will be displayed.  This message passing is an asynchronous
send, meaning that the call to \kw{CkPrintf} returns immediately after the
message has been sent, and most likely before the message has actually
been received, processed, and displayed. \footnote{Because of
communication latencies, the following scenario is actually possible:
Chare 1 does a \kw{Ckprintf} from processor 1, then creates chare 2 on
processor 2.  After chare 2's creation, it calls \kw{CkPrintf}, and the
message from chare 2 is displayed before the one from chare 1.}
}

\function{void CkError(format [, arg]*))} \index{CkError} \index{input/output} 
\desc{Like \kw{CkPrintf}, but used to print error messages on \texttt{stderr}.}

\function{int CkScanf(format [, arg]*)} \index{CkScanf} \index{input/output}
\desc{This call is used for atomic terminal input. Its usage is similar to
{\tt scanf} in C.  A call to \kw{CkScanf}, unlike \kw{CkPrintf},
blocks all execution on the processor it is called from, and returns
only after all input has been retrieved.
}

For \CC\ style stream-based I/O, \charmpp\ offers \kw{ckin},
\kw{ckout}, and \kw{ckerr} in the place of cin, cout, and cerr.  The
\CC streams and their \charmpp\ equivalents are related in the same
manner as printf and scanf are to \kw{CkPrintf} and \kw{CkScanf}.  The
\charmpp\ streams are all used through the same interface as the \CC\ 
streams, and all behave in a slightly different way, just like C-style
I/O. \kw{ckout} and \kw{ckerr} both have the same idiosyncratic
behavior as \kw{CkPrintf}, and \kw{ckin} behaves in the same way as
\kw{CkScanf}.
