プロが教える店舗&オフィスのセキュリティ対策術

何をすればいいのかがさっぱりです

文字列を入力
入力された文字列について

次の(1)~(6)のすべてを表示するプログラムを作成
(1) 全文字の合計文字数
(2) 数字の文字数
(3) 英大文字の文字数
(4) 英小文字の文字数
(5) 空白の文字数
(6) その他の文字の文字数

データの読み込みはgetchar 関数を使用

実行例
total = (1)
numeric= (2)
large = (3)
small = (4)
space = (5)
other = (1)-(2)(3)(4)(5)

よろしくお願いします

A 回答 (4件)

今週もあとわずか。

この問いも2ページへ回されましたから、もういいでしょう。

UNIX系として、リダイレクトで取り込んで処理することが条件です。
データの入力文字列は、Japan Times の記事を testfile とすれば
http://search.japantimes.co.jp/cgi-bin/nn2010111 …
↓のように出力されます。

なお、プログラム内容は見てのとおりチョー簡単です。それは講義をきちんと受けていればわかる問題ですから、くれぐれも さ・ぼ・ら・ぬ よう肝に命じてください。
起動は「./a.out<testfile」です。





----- testfile -----
Japan, U.S. to launch talks to bolster defense

WASHINGTON (Kyodo) Tokyo and Washington will soon launch working-level talks on strengthening defense cooperation in the event of an emergency affecting Japan, sources involved in Japan-U.S. relations said Tuesday.

The two countries decided to substantially strengthen the alliance in the face of the diplomatic clash with China over the Sept. 7 incident near the Senkaku Islands in the East China Sea and China's recent escalation of activities in the South China Sea, the sources said.

The plan is to renew and enhance the 1997 defense cooperation guidelines.


----- Result -----
Items:
total= 612
numeric= 5
large= 34
small= 459
space= 91
other= 23




/* Gcc on Mac OSX */
#include <stdio.h>
#include <ctype.h>

int main(void)
{
int c,total,numeric,large,small,space,other;
total=numeric=large=small=space=other=0;
while ((c=getchar())!=EOF) {
putchar(c);
total++;
if(isdigit(c)) numeric++;
else if(isupper(c)) large++;
else if(islower(c)) small++;
else if(c==' ') space++;
else other++;
}
printf("\nItems:\n");
printf("\ttotal= %d\n",total);
printf("\tnumeric= %d\n",numeric);
printf("\tlarge= %d\n",large);
printf("\tsmall= %d\n",small);
printf("\tspace= %d\n", space);
printf("\tother= %d\n", other);
return 0;
}

参考URL:http://www9.plala.or.jp/sgwr-t/c/sec07.html
    • good
    • 0
この回答へのお礼

懇切丁寧に有難う御座いました

お礼日時:2010/11/21 01:46

>よろしくお願いします


>>何をすればいいのか
>次の(1)~(6)のすべてを表示するプログラムを作成
>(1) 全文字の合計文字数
>(2) 数字の文字数
>(3) 英大文字の文字数
>(4) 英小文字の文字数
>(5) 空白の文字数
>(6) その他の文字の文字数
何を質問されているのかわかりません。
もう少し質問を明確にしてください。

>何をすれば。。。
上記を表示するプログラムを
作ればいいのではないですか?
    • good
    • 0
この回答へのお礼

分かりにくくてごめんなさい

お礼日時:2010/11/21 01:45

int total=0;


while(getchar()!=EOF)
{
total++;
}
printf("total=%d\n",total);
    • good
    • 0
この回答へのお礼

ありがとです

お礼日時:2010/11/21 01:45

(1) 全文字の合計文字数 strlen()で


(2) 数字の文字数 isdigit()で
(3) 英大文字の文字数 isupper()で
(4) 英小文字の文字数 islower()で
(5) 空白の文字数 スペース=0x20を使う
    • good
    • 0
この回答へのお礼

ありがとうございました。

お礼日時:2010/11/21 01:44

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!