の戻り値はscanf()
ためman
ページが返された値(ないパラメータ値)について言っていることである使用
これはつまるところ何
RETURN VALUE
On success, these functions return the number of input items success‐
fully matched and assigned; this can be fewer than provided for, or
even zero, in the event of an early matching failure.
The value EOF is returned if the end of input is reached before either
the first successful conversion or a matching failure occurs. EOF is
also returned if a read error occurs, in which case the error indicator
for the stream (see ferror(3)) is set, and errno is set to indicate the
error.
:
システム機能から返されるエラー条件を常にチェックします。常にバッファのオーバーフローを回避するために、入力バッファの長さよりも1つ少ないMAX文字修飾子を使用
:に `
scanf("%s",&text[count]);
:
は、これを変更示唆しています。このようなバッファオーバーフローは未定義の動作であり、segaultイベントにつながる可能性があります。
int retScanf = scanf("%99s", &text[count]);
switch(retScanf)
{
case 1: // normal return
// handle string input
// this is where to check for 'end'
break;
case EOF: // ctrl-z return
// user entered <ctrl>-z
break;
case 0: // invalid input return
// user entered only 'white space' (space, tab, newline)
break;
default: // should always provide for unexpected 'switch case'
// display error message here
break;
} // end switch
「Ctr + Z」がエミュレートする環境を確認してください。 scanf()の返り値を比較すると、 –
あなたが送信するシグナル、すなわち 'SIGTSTP'を処理する必要があります。 GoogleでCのシグナルを処理するために – Dunno
これを見てくださいhttp://stackoverflow.com/questions/16132971/how-to-send-ctrlz-in-c –