F
F
Firetheestle2016-06-15 23:01:43
C++ / C#
Firetheestle, 2016-06-15 23:01:43

How to get rid of invalid type argument of unary (have) error in C?

I wrote the code, it seems to be correct, but I got errors from which I can’t get rid of even looking at the answers on foreign forums. Pasted the whole code. I write in Atom, I compile via gcc
Here is what the compiler produces:

spoiler

C:\Users\Firetheestle\YandexDisk\ТТИТ\Labs>gcc Kimlaba7.c -o Kimlaba7.exe
Kimlaba7.c: В функции :
Kimlaba7.c:20:23: ошибка: invalid type argument of unary <*> (have )
printf("%2d \n",*(X+i*4+j));
^
Kimlaba7.c: В функции :
Kimlaba7.c:31:19: ошибка: invalid type argument of unary <*> (have )
int i=0,j=0,max=*(X+i*4+j),maxj=0;;
^
Kimlaba7.c:34:14: ошибка: invalid type argument of unary <*> (have )
if(max>*(X+i*4+j)){
^
Kimlaba7.c:35:13: ошибка: invalid type argument of unary <*> (have )
max=*(X+i*4+j);
^
Kimlaba7.c:39:5: ошибка: invalid type argument of unary <*> (have )
*(X+i*4+max)=0;
^
Kimlaba7.c: В функции :
Kimlaba7.c:45:8: предупреждение: при передаче аргумента 1 указатель преобразуется в целое без приведения типа
VVOD(A);
^
Kimlaba7.c:6:5: замечание: expected but argument is of type
int VVOD(int X){
^
Kimlaba7.c:46:9: предупреждение: при передаче аргумента 1 указатель преобразуется в целое без приведения типа
VIVOD(A);
^
Kimlaba7.c:15:5: замечание: expected but argument is of type
int VIVOD(int X){
^
Kimlaba7.c:47:15: предупреждение: при передаче аргумента 1 указатель преобразуется в целое без приведения типа
MAXANDOBMEN(A);
^
Kimlaba7.c:30:5: замечание: expected but argument is of type
int MAXANDOBMEN(int X){

I compile with the command:
gcc Kimlaba7.c -o Kimlaba7.exe
And here is the code itself:
/*
Дана матрица В(8,8). Заменить в каждой строке  матрицы
      максимальный элемент нулем.
*/
#include<stdio.h>
int VVOD(int X){
  int i,j;
  printf("Vvedite massive:\n");
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      scanf("%d",X+i*4+j );
    }
  }
}
int VIVOD(int X){
  int i,j,k=0;
  printf("Vivod massiva \n");
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      printf("%2d \n",*(X+i*4+j));
      k++;
      if(k==4){
        printf("\n");
        k=0;
      }

    }
  }
}
int MAXANDOBMEN(int X){
  int i=0,j=0,max=*(X+i*4+j),maxj=0;;
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      if(max>*(X+i*4+j)){
        max=*(X+i*4+j);
        maxj=j;
      }
    }
    *(X+i*4+max)=0;
  }

}
int main(){
  int A[4][4];
  VVOD(A);
  VIVOD(A);
  MAXANDOBMEN(A);
}

Please help me figure it out ;z
THE PROBLEM IS SOLVED HERE IS THE WORKING CODE:
/*
Дана матрица В(8,8). Заменить в каждой строке  матрицы
      максимальный элемент нулем.
*/
#include<stdio.h>
int VVOD(int* X){
  int i,j;
  printf("Vvedite massive:\n");
  for(i=0;i<4;i++){
    for(j=0;j<4;j++){
      scanf("%d", X+i*4+j );
    }
  }
}
int VIVOD(int* X){
  int i,j,k = 0;
  printf("Vivod massiva \n");
  for(i=0; i < 4; i++){
    for(j=0; j < 4; j++){
      printf("%3d", *(X+i*4+j));
      k++;
      if(k == 4){
        printf("\n");
        k = 0;
      }

    }
  }
}
int MAXANDOBMEN(int* X){
  int i = 0, j = 0, k = 0,max = 0, maxj = 0;
  for(i = 0; i < 4; i++){
    max = *(X+i*4+j);
    for(j = 0; j < 4; j++){
      if(max < *(X+i*4+j)){
        max = *(X+i*4+j);
        maxj = j;
      }
    }
    j=0;
    *(X+i*4+maxj) = 0;
}

}
int main(){
  int A[4][4];
  VVOD(*A);
  VIVOD(*A);
  MAXANDOBMEN(*A);
  VIVOD(*A);
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
tsarevfs, 2016-06-15
@Firetheestle

Read , (Don't be afraid of the C++ in the article's title, the only difference is how it prints to the screen). Now you are doing something strange. You declared the parameters as int, not *int.
PS I recommend immediately abandoning the caps in the names of functions, as it is customary to call constants. Transliteration is also not desirable, use a translator and learn English. After "," a space is placed. Before and before +-= etc. spaces are also customary.

#
#algooptimize #bottize, 2016-06-15
@user004

so it is written
*(X+i*4+max)=0;
you can't do that
X+i*4+max is not a pointer
In VVod it's not at all clear what was passed.
You would be defined, with pointers, links or with what you work. Porridge

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question