Script started on Fri Jan 21 18:21:31 2000 [hazel:]% cat kadai.c #include main() { char s[10000]; char fin[100]; char fout[100]; int n; int i; FILE *in,*out; printf("Input file name: "); /* ファイル名の入力 */ scanf("%s",fin); printf("Output file name: "); scanf("%s",fout); if ((in=fopen(fin,"r"))==NULL) { /* ファイルオープン */ printf("入力ファイルをオープンできません"); exit(1); } if ((out=fopen(fout,"w"))==NULL) { printf("出力ファイルをオープンできません"); exit(1); } fgets(s,10000,in); /* 入力 */ n=0; i=0; while( s[i] != 0 ){ if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z')){ if(i==0 || (!((s[i-1]>='a' && s[i-1]<='z') || (s[i-1]>='A' && s[i-1]<='Z')))){ n = n + 1; } } i = i + 1; } fprintf(out,"String= %s \n", s ); /* 出力 */ fprintf(out,"Word count=%d\n", n ); fclose(in); /* クローズ */ fclose(out); } [hazel:]% gcc -o kadai kadai.c [hazel:]% cat test.txt If you have any questions, raise your hands. [hazel:]% kadai Input file name: test.txt Output file name: out.txt [hazel:]% cat out.txt String= If you have any questions, raise your hands. Word count=8 [hazel:]% exit script done on Fri Jan 21 18:22:31 2000