Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
scanf() を間違った方法で使用していますか?
char *input; scanf("%s", input); printf("%s\n", input);
これは実行時に失敗します。
a を宣言するchar *とポインタが作成されるだけで、文字列にメモリは割り当てられません。入力用にメモリを割り当てる必要があります。を介してmalloc(およびfree完了時に)動的に行うか、 のような静的サイズの配列を宣言できますchar input[100]。
char *
malloc
free
char input[100]
char *input;と置き換えますchar input[1024] = {0};
char *input;
char input[1024] = {0};
scanf に渡すパラメーターが、入力を保持できるバッファーを指すようにする必要があります