/* キーボードからファイル名を読み込み、そのファイル中の 数字文字の個数を個数をカウントして画面に表示するプログラムを作成せよ。 */ #include int main(void) { FILE *fp; char fname[256]; int ch; int cnt = 0; printf("ファイル名を指定してください:"); scanf("%s", fname); if((fp = fopen(fname, "r")) == NULL) puts("\aファイルをオープン出来ません。"); else { while((ch = fgetc(fp)) != EOF) if(ch >= '0' && ch <= '9') cnt++; fclose(fp); printf("指定されたファイルは%d個数字文字がありました。\n", cnt); } return 0; }