課題では文字の種類はASCIIコードに限られていて、改行コードなど特殊文字も
一つの文字として扱わなければならないのですが、その特殊文字の数え方が分かりません。
一応、自分でやってみたのですが印字な可能な文字しか数えることが出来ませんでした(^_^;)
よろしくお願いします。
#include <stdio.h> #include <stdlib.h> int data[256]; void countLtr(FILE *fp); int main(void) { FILE *fp; int c; //強制終了 if ((fp = fopen("test.txt", "r")) == NULL) { fprintf ( stderr, "Can't open.\n" ); exit (2); } printf("test.txt\n"); countLtr(fp) ; printf("---------\n"); for (c = 0; c <= 127; c++){ printf("%c:%d\t", c, data[c] ); } fclose(fp); return 0; } //ファイル中の英文字の出現頻度を調べる関数 void countLtr(FILE *fp) { int c; while ((c = getc(fp)) != EOF) if (c >= 0 && c <= 127){ data[c]++; } }