happy_1[1]% cat kadai11-1.c #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); } happy_1[2]% gcc -o kadai11-1 kadai11-1.c happy_1[3]% cat test.txt If you have any questions, raise your hands. happy_1[4]% kadai11-1 Input file name: test.txt Output file name: result.txt happy_1[5]% cat result.txt String= If you have any questions, raise your hands. Word count=8