简体   繁体   中英

Parameter name omitted in my function

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");
  }
}

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');
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM