なぜ2番目のscanfが何の入力をしないのですか? %sは文字列をカタカナできますか?2つのscanf(%s)を同時に使用する際に何が間違っていますか
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
char string1[50];
char string2[50];
scanf("%[^\n]s",string1);
scanf("%[^\n]s",string2);
printf("\nfirst string :%s \n",string1);
printf("\nsecnd string :%s \n",string2);
return 0;
}
入力:最初の文字列は:これはBBC 2番目の文字列である:{いくつかの文字記号}
大丈夫ありがとうございました。gets()を使用することなく、適切な方法が必要です。 –
これは、状況がscanf( "%s"、array1)で、次の行scanf( "%s"、array1)が同じ配列の場合です。出力 –
@deepakpandey入力がバッファサイズを超えた場合、バッファオーバーランが発生します。サイズを明示的に制限する: 'scanf("%9s "、bufOfTen)'ヌルターミネータのために余分なバイトが必要です。 – dasblinkenlight