为什么这段代码在代码块中不起作用...我可以在文本中输入但是我无法打印所需的直方图?代码的目的是打印直方图。这是C编程语言中的练习1-13
#include <stdio.h>
#define MAXHIST 15
#define MAXWORD 11
#define IN 1
#define OUT 0
main()
{
int c, i, nc, state;
int len;
int maxvalue;
int ovflow;
int wl[MAXWORD];
state = OUT;
nc = 0;
ovflow = 0;
for(i=0; i < MAXWORD; ++i)
wl[i] = 0;
while(( c = getchar()) !=EOF) {
if (c==' '|| c=='\n'|| c == '\t' ){
state = OUT;
if (nc>0)
if (nc < MAXWORD)
++wl[nc];
else
++ovflow;
nc=0;
}else if (state == OUT){
state = IN;
nc = 1;
}else
++nc;
}
maxvalue = 0;
for (i = 1; 1<MAXWORD; ++i)
if (wl[i] > maxvalue)
maxvalue = wl[i];
for (i=1; i<MAXWORD; ++i){
printf("%5d - %5d : ", i, wl[i]);
if (wl[i]> 0){
if ((len=wl[i] * MAXHIST / maxvalue) <=0)
len = 1;
}else
len = 0;
while (len > 0 ) {
putchar('*');
--len;
}
putchar('\n');
}
if (ovflow > 0)
printf("There are %d words >= %d\n", ovflow, MAXWORD);
}
答案 0 :(得分:2)
这一行是个大问题:
mp = function(k,v){
machine_id=v$machine_id
keyval(machine_id,1) }
rd = function(k,v) keyval(k,length(v))
mapreduce(input = mapreduce(input='\user\cloudera\sample.json', input.format="json" , map=function(k,v) keyval(k,v)) , map=mp, reduce = rd)
您有一个拼写错误,您可以将for (i = 1; 1<MAXWORD; ++i)
与1
进行比较。这条线应该是这样的:
MAXWORD
也不确定为什么在进入循环之前递增for (i = 1; i<MAXWORD; ++i)
而不是之后。