Last modified: Thu Apr 10 09:24:57 JST 2008
入力を標準入力からファイルに切替える:
scanf関数を利用した例:
#include <stdio.h> main() { int n; int counter = 0; while(scanf("%d", &n) > 0) { counter++; printf("%d\t%d\n", counter, n); } printf("データ数 = %d\n", counter); }
while( scanf("%d", &n) > 0 ) { ... }
#include <stdio.h> #define SIZE 81 main() { char str[SIZE]; int n; int counter = 0; while(fgets(str, SIZE, stdin)) { counter++; n = atoi(str); printf("%d\t%d\n", counter, n); } printf("データ数 = %d\n", counter); }