C复习笔记(6)-6.24
来源:互联网 发布:ios短信群发软件 编辑:程序博客网 时间:2024/05/06 10:44
6.24
A improve version for the answer book!
Notice:
int isprint ( int c );
Check if character is printable, I first use it to print the x-axis, then I found a extra variable, that’s the blank key, amazing! So, I used the isgraph()returns true for the same cases as isprint except for the whitespace characters (like ' '), which return true when checked with isprint but false when checked with isgraph.
#include <stdio.h>
/* NUM_CHARS should really be CHAR_MAX but K&R haven't covered that at this stage in the book */
#define NUM_CHARS 256
int main(void)
{
int c;
long freqarr[NUM_CHARS + 1];
long thisval = 0;
long maxval = 0;
int thisidx = 0;
for(thisidx = 0; thisidx <= NUM_CHARS; thisidx++)
{
freqarr[thisidx] = 0;
}
while((c = getchar()) != EOF)
{
if(c < NUM_CHARS)
{
thisval = ++freqarr[c];
if(thisval > maxval)
{
maxval = thisval;
}
}
else
{
thisval = ++freqarr[NUM_CHARS];
if(thisval > maxval)
{
maxval = thisval;
}
}
}
for(thisval = maxval; thisval > 0; thisval--)
{
printf("%4d |", thisval);
for(thisidx = 0; thisidx <= NUM_CHARS; thisidx++)
{
if(isgraph(thisidx))
{
if(freqarr[thisidx] >= thisval)
{
printf("*");
}
else if(freqarr[thisidx] > 0)
{
printf(" ");
}
}
}
printf("/n");
}
printf(" +");
for(thisidx = 0; thisidx <= NUM_CHARS; thisidx++)
{
if(freqarr[thisidx] > 0)
{
printf("-");
}
}
printf("/n ");
/*print x-axis */
for(thisidx = 0; thisidx < NUM_CHARS; thisidx++)
{
if(freqarr[thisidx] > 0)
{
if(isgraph(thisidx))
putchar(thisidx);
}
}
printf("/n ");
/*Deal this the extrmely situation*/
if(freqarr[NUM_CHARS] > 0)
{
if(isgraph(NUM_CHARS))
putchar(NUM_CHARS);
printf("/n");
}
printf("/n");
return 0;
}
- C复习笔记(6)-6.24
- C语言复习笔记 6
- c复习笔记
- C语言复习笔记
- C语言复习笔记
- C笔记复习
- C--复习笔记
- C & C++ 复习笔记
- C复习笔记(1)-6.16
- C复习笔记(2)-6.18
- C复习笔记(3)-6.19
- C复习笔记(4)-6.20
- C复习笔记(5)-6.23
- C复习笔记(7)-7.4
- C复习笔记(7)-7.4
- c语言复习笔记1
- C语言老师复习笔记
- C语言复习笔记 1
- Skype录音答录机 编程思路阐述和源代码下载
- ASCII码
- 数据库约束
- 踏上跳槽之路
- 设置tomcat 5.5版本的Log4j日志功能
- C复习笔记(6)-6.24
- 设计方案被否决
- My Money ,My life,My god!I hate!
- 另一个,Ubuntu英文状态下安装scim输入法的方法
- 在曲折中学习C#
- 在曲折中学习C#
- 正确获取当前URL
- MYSQL数据类型笔记-1
- winrunner7.6破解