# problem in histogram word

This is a discussion on problem in histogram word within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define SIZE 100 int main(void) { char *name; int i,c,x; int histogram[10]; name=malloc(sizeof ...

1. ## problem in histogram word

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100
int main(void)
{
char *name;
int i,c,x;
int histogram[10];
name=malloc(sizeof (char) * SIZE);
x=0;
for(i=0;i<10;i++)
histogram[i]=0;
for(;;){
fgets(name,SIZE,stdin);
x=strlen(name);
puts(name);
/*next our test in histogram*/
if (x >= '0' && x <= '9')
++histogram[x-'0'];
/*next step showing it*/
puts("its histogram is\n");
for(i=0;i<10;i++){
printf("%d ",histogram[i]);}
puts("\n");
/*intilising all back to 0 and freeing back*/
x=0;
for(i=0;i<10;i++)
histogram[i]=0;
free(name);
name=malloc(sizeof (char) * SIZE);
continue;}
return 0;
}```
it alawys shows the histogram alawys 0 i dunno why;

2. I don't really understand what you want, but i think the wrong piece is the line

Code:
`x = strlen(name)`
That means, x is the length of the input. Then you're checking if x represents a digit. propably no. What you wanted is:

Code:
`x = name[0]`
`x = getchar();`