Files
2025-04-27 14:34:55 +09:00

33 lines
1.6 KiB
TeX
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

\section{今回の構文}
\subsection{\texttt{scanf}関数}
\texttt{scanf}関数は標準入力から文字列を読み取り、指定された書式に沿って解釈し、解釈結果の値を指定された場所に保存する。
ここでいう場所とは変数のアドレスのことである。
書式は\texttt{printf}関数と同じものである。\cite{cppref_scanf}
\defaultlistingstyle
\begin{lstlisting}[language=C,title={\texttt{scanf}関数}]
scanf("<書式>", <変数1へのアドレス>, <変数2へのアドレス>, ...);
\end{lstlisting}
\begin{itembox}[l]{\textrm{コラム:標準入出力関数の戻り値}}
標準入出力関数には\texttt{void}型を返す関数はほとんど定義されていない。
\vspace{0.25cm}
\begin{center}
表1主な標準入出力関数の戻り値\cite{cppref_stdio}
\vspace{0.125cm}
\begin{tabular}{|ccl|}
\hline
関数 && \multicolumn{1}{c|}{概要} \\ \hline \hline
\texttt{scanf}& \texttt{int} & 正常に読み込まれた変数の数、0または\texttt{EOF}定数はエラーとなる \\ \hline
\texttt{printf}& \texttt{int} & \vtop{\hbox{\strut バッファーやストリームに書き込まれた文字の数、}\hbox{\strut 負の値はエラーとなる}} \\ \hline
\vtop{\hbox{\strut \texttt{setbuf, rewind,}} \hbox{\strut \texttt{clearerr, perror}}} & \texttt{void} & \vtop{\hbox{\strut これらの関数のみ値を返さない、}\hbox{\strut エラーになり得る処理ではないから}} \\ \hline
\end{tabular}
\end{center}
\end{itembox}