C:在读取字符串时,如何读取整个ascii表的频率计数(尽可能接近)

C:在读取字符串时,如何读取整个ascii表的频率计数(尽可能接近),c,string,count,C,String,Count,从本网站 他们有一个例子,可以计算a-z,但不能计算a-z或空格或标准标点 while ( string[c] != '\0' ) { /* Considering characters from 'a' to 'z' only */ if ( string[c] >= 'a' && string[c] <= 'z' ) count[string[c]-'a']++; c++; } for ( c

从本网站 他们有一个例子,可以计算a-z,但不能计算a-z或空格或标准标点

  while ( string[c] != '\0' )
  {
     /* Considering characters from 'a' to 'z' only */

     if ( string[c] >= 'a' && string[c] <= 'z' ) 
        count[string[c]-'a']++;

     c++;
  }

  for ( c = 0 ; c < 26 ; c++ )
  {
     if( count[c] != 0 )
while(字符串[c]!='\0')
{
/*仅考虑从“a”到“z”的字符*/

如果(string[c]>='a'&&string[c]我不确定我是否理解了你的问题,但我担心在提问之前我看不到有人试图解决这个问题

int count[ 256 ] ; // - make sure you change your declaration from [ 26 ]!

while ( string[c] != '\0' )
{
   count[( unsigned char )string[c]]++;
   c++;
}

for ( c = 1 ; c < 256 ; c++ ) // no point to check c == 0
{
   if( count[c] != 0 )
int count[256];//-请确保将您的声明从[26]更改!
while(字符串[c]!='\0')
{
计数[(无符号字符)字符串[c]]++;
C++;
}
对于(c=1;c<256;C++)/ /没有检查C==0的点
{
如果(计数[c]!=0)

我不确定我是否理解了你的问题,但我担心在提问之前我看不到有人试图解决这个问题

int count[ 256 ] ; // - make sure you change your declaration from [ 26 ]!

while ( string[c] != '\0' )
{
   count[( unsigned char )string[c]]++;
   c++;
}

for ( c = 1 ; c < 256 ; c++ ) // no point to check c == 0
{
   if( count[c] != 0 )
int count[256];//-请确保将您的声明从[26]更改!
while(字符串[c]!='\0')
{
计数[(无符号字符)字符串[c]]++;
C++;
}
对于(c=1;c<256;C++)/ /没有检查C==0的点
{
如果(计数[c]!=0)

要计算字符串中的所有字符,请使用
int a[256]
并将字符串中的字符用作数组的索引和增量:

int counts[256] = { 0 }; /* Initialize all elements to zero. */

while (string[c]) counts[(unsigned char)string[c++]]++;

要计算字符串中的所有字符,请使用an
int a[256]
,并将字符串中的字符用作数组的索引和增量:

int counts[256] = { 0 }; /* Initialize all elements to zero. */

while (string[c]) counts[(unsigned char)string[c++]]++;

什么是不可读的?什么是不可读的?你的意图是允许并计算所有8位字符。好的,但是你需要记住,
char
可以被签名。你的意图是允许并计算所有8位字符。好的,但是你需要记住,
char
可以被签名。@Grzegorz,注意这是C,所以没有
>静态施法
)@hmjd:Grrr。我是盲人。我没有注意到“C:…thingi。谢谢你们两个!@Grzegorz,注意这是C所以没有
静态施法
)@hmjd:Grrr。我是盲人。我没有注意到“C:…thingi。谢谢你们两个!