可能性の重複:
c program for 20 chars and reports quantity of each[SOLVED]文字列を読み込み、各文字が何回出現するかを示すCプログラムを作成しますか?
これは私がこれまで持っているものです。しかし、私がプログラムを使用して「Qwerty」と入力すると、Qを5回使用したというメッセージが表示されます。助けてください。それは常に文字列の最初の文字だから
c=*line;
:
#include <stdio.h>
#include <string.h>
void readData(char line[], int size)
{
printf("Enter a string no longer than 20 characters: ");
fgets(line, size, stdin);
line[strlen(line) - 1] = '\0';
strupr(line);
printf("You Entered %s\n", line);
return;
}
void counter(char line[], int counts[])
{
int i;
char c;
for (i = 0; i < strlen(line); i++)
{
c = *line;
if (c >= 'A' && c <= 'Z')
{
counts[c - 'A']++;
}
else
{
counts[26]++;
}
}
return;
}
void printer(int counts[])
{
int i;
for (i=0; i < 26; i++)
{
printf("there are %d occurances of %c\n", counts[i], i + 'A');
}
printf("there are %d occurances of non alphabetic\n", counts[26]);
return;
}
int main()
{
const int SIZE = 22;
char line[22] = {'\0'};
int counts[27] = { 0 };
readData(line, SIZE);
counter(line, counts);
printer(counts);
return(0);
}
あなたはそれを読みやすいようにフォーマットできますか?ブロッククォート機能を使用します。 –
sozがあなたのために編集しました – killerbill09
[20文字の文字列を読み込み、各文字が何回出現するかを示すCプログラムを作成しますか?](http://stackoverflow.com/questions/5975413/create-ac-プログラムでは、20文字の文字列と数えられる多くの文字列)と[Cプログラミングの質問?](http://stackoverflow.com/questions/5978708/c-プログラミングの質問) –