Expression must have a pointer to object type in C

anansharm

I am trying to use pointers in functions and arrays and when I call the report function in main, I keep getting an error Expression must have a pointer to object type. I have tried everything. Nothing seem to be working. Can anyone please let me know what I am doing wrong?

Please note: without the report function, if I call the other functions separately in main it works. It's not working only with the report function.

#include <stdio.h>
#include <conio.h>

void print(int *list, int row_count, int column_count);
void rowaverage(int *list, int row_count, int column_count);
void allaverage(int *list, int row_count, int column_count);
void largest(int *list, int row_count, int column_count);
void report(int *list, int row_count, int column_count);

int main()
{
  int i = 1, row, column;
  int list[3][5];
  printf("Enter 3 sets of 5 integers::\n");
  for (row = 0; row < 3; row++)
  {
    printf("Elements in the %d set are ::\n", row);
    for (column = 0; column < 5; column++)
    {
      printf("Element No. %d is ", i++);
      scanf("%d", &list[row][column]);
    }
    printf("\n");
    i = 1;
  }
  printf("The elements in array are:\n");

  report(&list[0][0], row, column);

  getch();
  return 0;
}

void print(int *list, int row_count, int column_count)
{
  int column, row;
  for (row = 0; row < row_count; row++)
  {
    for (column = 0; column < column_count; column++)
    {
      printf("%8d", *(list + row * column_count + column));
    }
    printf("\n");
  }
}

void rowaverage(int *list, int row_count, int column_count)
{
  int column, row;
  for (row = 0; row < row_count; row++)
  {
    float sum = 0, count = 0;
    for (column = 0; column < column_count; column++)
    {
      sum += *(list + row * column_count + column);
      count++;
    }
    printf("Average of row %d is %.2f\n", row, (sum / count));
  }
}

void allaverage(int *list, int row_count, int column_count)
{
  int column, row;
  float sum = 0, count = 0;
  for (row = 0; row < row_count; row++)
  {
    for (column = 0; column < column_count; column++)
    {
      sum += *(list + row * column_count + column);
      count++;
    }
  }
  printf("Average of all elements in array is %.2f\n", (sum / count));
}

void largest(int *list, int row_count, int column_count)
{
  int column = 0, row = 0;
  int largest = *(list + row * column_count + column);
  for (row = 0; row < row_count; row++)
  {
    for (column = 0; column < column_count; column++)
    {
      if (largest < *(list + row * column_count + column))
      {
        largest = *(list + row * column_count + column);
      }
    }
  }
  printf("The largest number in the array is %d\n", largest);
}

void report(int *list, int row_count, int column_count)
{
  int row = 0, column = 0;
  print(list[0][0], row, column);
  printf("\n");
  rowaverage(list[0][0], row, column);
  printf("\n");
  allaverage(list[0][0], row, column);
  printf("\n");
  largest(list[0][0], row, column);
}
tyilmaz

In report function remove that line and see below report function:

int row = 0, column = 0;

In functions, use list as

int list[][5]

Call list as

list

not as

list[0][0]

Here is the complete code:

#include <stdio.h>
#include <stdlib.h>

void print(int list[][5], int row_count, int column_count)
{
    int column, row;

    for (row = 0; row < row_count; row++) {
        for (column = 0; column < column_count; column++)
            printf("%8d", list[row][column]);
        printf("\n");
    }
}

void rowaverage(int list[][5], int row_count, int column_count)
{
    int column, row;

    for (row = 0; row < row_count; row++) {
        float sum = 0, count = 0;
        for (column = 0; column < column_count; column++) {
            sum += list[row][column];
            count++;
        }
        printf("Average of row %d is %.2f\n", row, (sum / count));
    }
}

void allaverage(int list[][5], int row_count, int column_count)
{
    int column, row;
    float sum = 0, count = 0;

    for (row = 0; row < row_count; row++) {
        for (column = 0; column < column_count; column++) {
            sum += list[row][column];
            count++;
        }
    }

    printf("Average of all elements in array is %.2f\n", (sum / count));
}

void largest(int list[][5], int row_count, int column_count)
{
    int column = 0, row = 0;
    int largest = list[0][0];

    for (row = 0; row < row_count; row++) {
        for (column = 0; column < column_count; column++) {
            if (largest < list[row][column]) {
                largest = list[row][column];
            }
        }
    }

    printf("The largest number in the array is %d\n", largest);
}

void report(int list[][5], int row_count, int column_count)
{
    print(list, row_count, column_count);
    printf("\n");
    rowaverage(list, row_count, column_count);
    printf("\n");
    allaverage(list, row_count, column_count);
    printf("\n");
    largest(list, row_count, column_count);
}


int main()
{
    int i = 1, row, column;
    int list[3][5];

    printf("Enter 3 sets of 5 integers::\n");

    for (row = 0; row < 3; row++) {
        printf("Elements in the %d set are ::\n", row);
        for (column = 0; column < 5; column++) {
            printf("Element No. %d is ", i++);
            scanf("%d", &list[row][column]);
        }
        printf("\n");
        i = 1;
    }

    printf("The elements in array are:\n");

    report(list, row, column);

    return 0;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Pointer to a Vector of Vectors in a Function Gives 'expression must have pointer type' error

From Dev

Error: Expression must have integral or unscoped enum type

From Dev

C++ error -- expression must have integral or enum type -- getting this from a string with concatenation?

From Dev

C++ Expression must have constant value

From Dev

C# Type Object Pointer

From Dev

Expression must have integral or unscoped enum type

From Dev

c tree structure expression must have a class type

From Dev

Expression must be a pointer to a complete object type using simple pointer arithmetic

From Dev

"Expression must be a pointer to a complete object type"

From Dev

error: expression must have integral or enum type

From Dev

c++ expression must have a constant value

From Dev

"Expression must have class type" Error, trying to call a class function

From Dev

std::vector pointer - expression must have class type error

From Dev

expression must have arithmetic or unscoped enum type

From Dev

What is pointer to object type in C?

From Dev

error: expression must have pointer-to-object type

From Dev

error : expression must have class type

From Dev

Error. Expression must have a class type

From Dev

c tree structure expression must have a class type

From Dev

Expression must have pointer-to-class-type error

From Dev

"Expression must have class type" using undocumented library function

From Dev

"Expression must be a pointer to a complete object type"

From Dev

error: expression must have a class type

From Dev

error: expression must have integral or enum type

From Dev

Expression must have pointer to object type ERROR while executing C Program in Visual Studio

From Dev

When does error "expression must have pointer type" occur?

From Dev

Expression must have pointer type error on a pointer?

From Dev

During manual calling the destructor occurs the error: expression must be a pointer to a complete object type

From Dev

How to fix this Error expression must have a class type and C228?

Related Related

  1. 1

    Pointer to a Vector of Vectors in a Function Gives 'expression must have pointer type' error

  2. 2

    Error: Expression must have integral or unscoped enum type

  3. 3

    C++ error -- expression must have integral or enum type -- getting this from a string with concatenation?

  4. 4

    C++ Expression must have constant value

  5. 5

    C# Type Object Pointer

  6. 6

    Expression must have integral or unscoped enum type

  7. 7

    c tree structure expression must have a class type

  8. 8

    Expression must be a pointer to a complete object type using simple pointer arithmetic

  9. 9

    "Expression must be a pointer to a complete object type"

  10. 10

    error: expression must have integral or enum type

  11. 11

    c++ expression must have a constant value

  12. 12

    "Expression must have class type" Error, trying to call a class function

  13. 13

    std::vector pointer - expression must have class type error

  14. 14

    expression must have arithmetic or unscoped enum type

  15. 15

    What is pointer to object type in C?

  16. 16

    error: expression must have pointer-to-object type

  17. 17

    error : expression must have class type

  18. 18

    Error. Expression must have a class type

  19. 19

    c tree structure expression must have a class type

  20. 20

    Expression must have pointer-to-class-type error

  21. 21

    "Expression must have class type" using undocumented library function

  22. 22

    "Expression must be a pointer to a complete object type"

  23. 23

    error: expression must have a class type

  24. 24

    error: expression must have integral or enum type

  25. 25

    Expression must have pointer to object type ERROR while executing C Program in Visual Studio

  26. 26

    When does error "expression must have pointer type" occur?

  27. 27

    Expression must have pointer type error on a pointer?

  28. 28

    During manual calling the destructor occurs the error: expression must be a pointer to a complete object type

  29. 29

    How to fix this Error expression must have a class type and C228?

HotTag

Archive