私は C の初心者です。自分の機能を完了するために助けが必要です。
ミッションは次のとおりです。
string を受け入れる関数を作成しますmaximum length of 256 characters containing characters from 'a' to 'z'
。
各文字の出現回数を出力する関数。
例: 入出力abba
は次のようになります。
a = 2 b = 2 c = 0 d = 0 .... z = 0
関数の実行中は if を使用しないでください。
このプログラムを完成させるために、あなたの助けをお願いします。
これは私のコードです
#include "stdlib.h"
#include "conio.h"
#include "stdio.h"
#include "string.h"
#define size 256
void repeat(char *str);
void main()
{
char str[size];
printf("Please enter a string:\n");
flushall;
gets(str);
repeat(str);
system("pause");
return ;
}
void repeat(char *str)
{
char temp=strlen(str);
int i, count=0;
do
{
for (i=0; i<temp ; i++)
{
count += (*str == str[temp-i]);
}
printf("Char %c appears %d times\n ",*str,count);
count=0;
}
while(*(str++));
}
Please enter a string:
abbba
Char a appears 1 times
Char b appears 2 times
Char b appears 1 times
Char b appears 0 times
Char a appears 0 times
Char appears 0 times
Press any key to continue . . .
これが出力です!同じ建物でやりたいです。Char a が 2 回表示され、Chars b が 3 回表示されるようにする必要があります。