0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

C言語で5種類の文字を標準入力から受け取る方法

Last updated at Posted at 2023-07-26

学んだこと

・scanfの %c の前にスペースを入れることで、改行や空白文字を無視して1文字ずつ受け取れる。

#include <stdio.h>

int main() {
    char characters[5]; // 5つの文字を格納する配列
    for (int i = 0; i < 5; i++) {
        scanf(" %c", &characters[i]); 
    }

    printf("入力された文字は以下の通りです:\n");
    for (int i = 0; i < 5; i++) {
        printf("%c\n", characters[i]);
    }
    return 0;
}

入力例
a
b
c
d
e
出力例
入力された文字は以下の通りです:
a
b
c
d
e

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?