0

Parameter name omitted in function "histogram". What do I have to change on function "histogram"? The program is reading words and it prints their length (histogram). This is the main() function:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 99
#define M 99

int main(int argc, char *argv[])
{
  int a, j, count = 0, i, b = 0, word = 0, sum = 0;
  char x[N][M];

  for(i=0; i<N; i++) {
    printf("eisagete leksi,\ngrapste ****telos gia exit: ");
    scanf("%s", x[i]);
    a = strcmp(x[i], "****telos");
    if(a==0) break;
    count++;
  }

  for(i=0;i<count;i++)
    printf("%d leksi: %s\n",i+1, x[i]);

  printf("\n");

  for (j=0;j<count;j++){
    printf("%d :" , j+1);
    for(i=0; i<strlen(x[j]) ;i++){
    printf("*");}
    printf("\n\n");
  }

  while ((a=epilogi())!=5){
    switch (a){
      case 1: metrisileksewn(x);break;
      case 2: metrisixaraktirwn(x);break;
      case 3: diaflekseis(x);break;
      case 4: istograma(x);break;
      default:break;
    }
  }
}

There is one of my functions:

void histogram(char[N][M]){
  int i, j, count;
  char x[N][M];
  for (j=0; j<count; j++){
    for(i=0; i<strlen(x[j]); i++)
      printf("*");
    printf("\n");
  }
}
2
  • 1
    why not indent the code?
    – Ed Heal
    Apr 27, 2014 at 19:30
  • 1
    How about initialising int count in histogram() before using it, you know? Be nice to the C standard?
    – EOF
    Apr 27, 2014 at 19:34

1 Answer 1

0

You need to provide a name for the parameter.

void histogram(char y[N][M])

You can omit the name in a prototype declaration of a function, but not the definition.

You will also need to consider whether x is still needed, or whether the argument should be called x and the local variable deleted — I think that's likely what you need. But you also have to worry about count — where does that get initialized? It should probably be an extra parameter to the function. You should use putchar() to put single characters; it is best not to use printf() when there isn't a format string with at least one conversion specification in it.

void histogram(char x[][M], int count)
{
    for (int j = 0; j < count; j++)
    {
        int len = strlen(x[j]);
        for (int i = 0; i < len; i++)
            putchar('*');
        putchar('\n');
    }
}
3
  • You can omit the name, but it serves no purpose at that point. take C++ postfix operator++ for example: T operator++(int);
    – phyrrus9
    Apr 27, 2014 at 21:42
  • @phyrrus9: what is true in C++ is not true in C. In C (which the question is tagged with), you cannot omit parameter names from function definitions. The C++ feature would very useful in C too, but it is not a standard part of C. Apr 27, 2014 at 21:50
  • im aware of the differences. I was also wrong in that, sorry.
    – phyrrus9
    Apr 27, 2014 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.