少しおたずねします
Posted: 2008年7月07日(月) 11:14
下の添付ファイルは,文字列を入力してそれを大文字と小文字とそれ以外の文字(+,-など)にわけて,
それぞれをカウントするプログラムなのですが、どうも結果を表示するところでうまくいきません。
どうすればよいのでしょうか?
それぞれをカウントするプログラムなのですが、どうも結果を表示するところでうまくいきません。
どうすればよいのでしょうか?
#include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> int main(void) { char str[5][20]; // @ int i, j, count1, count2, count3; // @ 変数の初期化 memset(str, 0, sizeof(str)); count1 = count2 = count3 = 0; // @ printf("文字列を入力してください(一行19文字まで)\n"); // @ //文字列の入力 for(i=0; i<5; i++){ printf("%d行目を入力してください : ", i+1); // @ fgets(str, 20, stdin); // @ } printf("\n"); //入力した文字列の表示 for(j=0; j<5; j++){ printf("%s\n", str[j]); // @ } printf("大 小 その他\n"); // @ 文字数のカウント for(i=0; i<5; i++){ count1 = count2 = count3 = 0; for (j = 0; j < 20; j++) { if ((str[j] == '\0') || (str[j] == '\n')) break; // 文字列の終わり if(isupper(str[j]) == 0){ //大文字の場合 count1++; }else if(islower(str[j]) == 0){ //小文字の場合 count2++; }else{ //その他の場合 count3++; } } printf("%-8d %-8d %-8d\n", count1, count2, count3); } // @ return 0; }