Why not getting output in tabular form

#include <stdio.h>
#define MAXWIDTHSIZE 15
int main()
{
int char_input, charactercount;
char_input = charactercount = 0;
int wordcountstorage[MAXWIDTHSIZE] = {0};
char_input= getchar();
while (char_input!= EOF)
{
    while (char_input!= ' ' && char_input!= '\n' && char_input!= '\t' && charactercount < MAXWIDTHSIZE)
    {
        charactercount = charactercount + 1;
       char_input= getchar();
    }
    wordcountstorage[charactercount]++;
    charactercount = 0;
    char_input = getchar();
}
int histodisplay[MAXWIDTHSIZE][wordcountstorage[MAXWIDTHSIZE]];
for (int i = 0; i < MAXWIDTHSIZE; i++)
{
    for (int j = 0; j < wordcountstorage[i] + 1; j++)
    {
    if (wordcountstorage[i]== j)
      {
        printf("%d", histodisplay[i][j]);
      }
      else
      {
        printf("x");
      }
    }
      printf("\n");
}
printf("\n");
}
~/plurality/ $ make plurality
~/plurality/ $ ./plurality
rajeev is x and y
0
xx0
x0
x0
0
0
x0
0
0
0
0
0
0
0
0

I intend to get output in horizontal way resembling histogram .
!

It is intended to declare a two dimensional array with:

int histodisplay[MAXWIDTHSIZE][wordcountstorage[MAXWIDTHSIZE]];

Now I believe it is also needed to initialize the array. I am doing this way:

int histodisplay[MAXWIDTHSIZE][wordcountstorage[MAXWIDTHSIZE]] = {0};

This is the error:

~/plurality/ $ make plurality

plurality.c:20:18: error: variable-sized object may not be initialized

int histodisplay[MAXWIDTHSIZE][wordcountstorage[MAXWIDTHSIZE]] = {0};

^~~~~~~~~~~~

plurality.c:2:22: note: expanded from macro ‘MAXWIDTHSIZE’

#define MAXWIDTHSIZE 15

^~

1 error generated.

It will help to know why wordcountstorage[MAXWIDTHSIZE]] is wrong as suggested by an expert on another forum. What should be the correct way? My intuition is [MAXWIDTHSIZE] representing the x axis which will have 15 elements. wordcountstorage[MAXWIDTHSIZE] or wordcountstorage[15] representing the y axis with wordcountstorage[0] representing 0 wordcount frequency, wordcountstorage[1] representing 1 wordcount frequency…

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.