Skip to content

Instantly share code, notes, and snippets.

@bg1bgst333
Created February 21, 2026 00:28
Show Gist options
  • Select an option

  • Save bg1bgst333/b37412816a6498f1ed67b4dc16e73b48 to your computer and use it in GitHub Desktop.

Select an option

Save bg1bgst333/b37412816a6498f1ed67b4dc16e73b48 to your computer and use it in GitHub Desktop.
scanf#return_value
/* ヘッダファイルのインクルード */
#include <stdio.h> /* 標準入出力 */
/* main関数の定義 */
int main(void){
/* 変数・配列の宣言 */
int n;
int x;
int y;
char str1[16];
char str2[16];
char str3[16];
int ret_1;
int ret_2;
int ret_3;
/* 入力値が整数1つ. */
printf("n: ");
ret_1 = scanf("%d", &n);
printf("n = %d, ret_1 = %d\n", n, ret_1);
/* 入力値が整数2つ. */
printf("x y: ");
ret_2 = scanf("%d %d", &x, &y);
printf("x = %d, y = %d, ret_2 = %d\n", x, y, ret_2);
/* 入力値が文字列3つ. */
printf("str1 str2 str3: ");
ret_3 = scanf("%s %s %s", str1, str2, str3);
printf("str1 = %s, str2 = %s, str3 = %s, ret_3 = %d\n", str1, str2, str3, ret_3);
/* プログラムの終了 */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment