C言語1で困ってます・・・
Posted: 2011年6月30日(木) 15:32
問題
ファイルinput3.txtには複数の英単語のみが(空白や改行をはさみながら)記載されている。
input3.txtをEOF(End of File)まで読み込み、何文字の単語が何個あったのかを表示するプログラムを作成しなさい。このとき、1行には最大80文字記載されており、1単語の最大の文字数は15文字とする。
例)
1文字の単語: 20単語
3文字の単語: 10単語
5文字の単語: 4単語
全34単語
#include <stdio.h>
#include <ctype.h>
#define MAX (15)
int main()
{
__int count_of_letters = 0;
__int count_of_words[MAX + 1];
__int count_of_all_words = 0;
__int c;
__int i;
__for (i = 0; i <= MAX; i++){
____count_of_words = 0;
__}
__do {
____c = getchar();
____if (c != EOF && isalnum(c)){
______count_of_letters++;
____} else {
______if (count_of_letters){
________if (count_of_letters <= MAX){
__________count_of_words[count_of_letters]++;
________} else {
__________count_of_words[0]++;
________}
________count_of_all_words++;
________count_of_letters = 0;
______}
____}
__} while (c != EOF);
__for (i = 1; i <= MAX; i++){
____if (count_of_words){
______printf("%d文字の単語: %d単語\n", i, count_of_words);
____}
__}
__if (count_of_words[0]){
____printf("%d文字以上の単語: %d単語\n", MAX + 1, count_of_words[0]);
__}
__printf("\n全%d単語\n", count_of_all_words);
__return 0;
}
それ前の問題で利用したものと同様のinput3.txtを読み込む。キーボードから英単語を1つ入力し、その単語がinput3.txtに何個含まれるかを出力するプログラムを作成しなさい。
という問題です。
ファイルの読み込みはFPを使ってできるのですが英単語を1つ入力からinput3.txt内にいくつ含まれるかの処理ができません。
よろしければ協力おねがいします。
ファイルinput3.txtには複数の英単語のみが(空白や改行をはさみながら)記載されている。
input3.txtをEOF(End of File)まで読み込み、何文字の単語が何個あったのかを表示するプログラムを作成しなさい。このとき、1行には最大80文字記載されており、1単語の最大の文字数は15文字とする。
例)
1文字の単語: 20単語
3文字の単語: 10単語
5文字の単語: 4単語
全34単語
#include <stdio.h>
#include <ctype.h>
#define MAX (15)
int main()
{
__int count_of_letters = 0;
__int count_of_words[MAX + 1];
__int count_of_all_words = 0;
__int c;
__int i;
__for (i = 0; i <= MAX; i++){
____count_of_words = 0;
__}
__do {
____c = getchar();
____if (c != EOF && isalnum(c)){
______count_of_letters++;
____} else {
______if (count_of_letters){
________if (count_of_letters <= MAX){
__________count_of_words[count_of_letters]++;
________} else {
__________count_of_words[0]++;
________}
________count_of_all_words++;
________count_of_letters = 0;
______}
____}
__} while (c != EOF);
__for (i = 1; i <= MAX; i++){
____if (count_of_words){
______printf("%d文字の単語: %d単語\n", i, count_of_words);
____}
__}
__if (count_of_words[0]){
____printf("%d文字以上の単語: %d単語\n", MAX + 1, count_of_words[0]);
__}
__printf("\n全%d単語\n", count_of_all_words);
__return 0;
}
それ前の問題で利用したものと同様のinput3.txtを読み込む。キーボードから英単語を1つ入力し、その単語がinput3.txtに何個含まれるかを出力するプログラムを作成しなさい。
という問題です。
ファイルの読み込みはFPを使ってできるのですが英単語を1つ入力からinput3.txt内にいくつ含まれるかの処理ができません。
よろしければ協力おねがいします。