#include main() { char s[10000]; char fin[100]; char fout[100]; int n; int i; int a; FILE *in,*out; printf("Input file name: "); /* ファイル名の入力 */ scanf("%s",fin); printf("Output file name: "); scanf("%s",fout); if ((in=fopen(fin,"r"))==NULL) { /* ファイルオープン */ exit(1); } if ((out=fopen(fout,"w"))==NULL) { exit(1); } fgets(s,10000,in); /* 入力 */ n=0; i=0; a=0; while( s[i] != 0 ){ if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){ if( a == 0 ){ n = n + 1; } a = 1; }else{ a = 0; } i = i + 1; } fprintf(out,"String= %s \n", s ); /* 出力 */ fprintf(out,"Word count=%d\n", n ); fclose(in); /* クローズ */ fclose(out); }