Error invalid type argument of unary have float

Ответили на вопрос 2 человека. Оцените лучшие ответы! И подпишитесь на вопрос, чтобы узнавать о появлении новых ответов.

Написал код, вроде правильный,но вылезли ошибки от которых я не могу избавиться даже смотря ответы на зарубежных форумах. Вставил код целиком. Пишу в Atom компилирую через gcc
Вот что выдает компилятор:

spoiler

C:UsersFiretheestleYandexDiskТТИТ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){

Компилирую командой:
gcc Kimlaba7.c -o Kimlaba7.exe
А вот сам код:

/*
Дана матрица В(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);
}

Помогите пожалуйста разобраться ;з
ПРОБЛЕМА РЕШЕНА ВОТ РАБОЧИЙ КОД:

/*
Дана матрица В(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);
}

Error: invalid type argument of unary ‘*’ (have ‘float’)
heres the function it appears in.

this is my first time working with pointers, stay tuned for further derps

 void printArray(float *array, int hours)
{
    int x = hours;
    cout << "Number of hours each student spent : " << endl;

    for (x = 0; x <= size; x++)
    {
        cout << *array[x] << "  " << endl;
                    ^^ Error is here
    }
}

second error is — invalid tyoes ‘int[int]’ for array subscript
found in this function

    void getFBTData(int size, int hours)
{
    for (int count = 0; count < size; count++)
    {
        cout << "Enter number if hours each student spent.  " << count + 1;
        cin >> hours[count];
                    ^^ Error is here
    }
    cin.sync();
}

asked Apr 6, 2014 at 2:01

user3502479's user avatar

2

Well, you really need to learn how to dereference and subscript. Some basic rules:

cout << *array[x] << "  " << endl; //same as *(array[x]), cannot derefence float
         array[x] //change to

cin >> hours[count]; //hours is int, cannot subscript

void getFBTData(int size, int *hours) //change to pointer

answered Apr 6, 2014 at 2:11

yizzlez's user avatar

yizzlezyizzlez

8,6994 gold badges29 silver badges44 bronze badges

  • Forum
  • Beginners
  • invalid type argument of ‘unary *’

invalid type argument of ‘unary *’

I keep getting a invalid type argument of ‘unary *’ error and im not sure how to fix it.

my program worked fine before i added this bit

1
2
3
4
5
	float mwtheta ;
	mwtheta = 1 + f2[0]*f2[1]*(1/2*(*3* (cos(theta[0]))^2 *-1 )) 
			+ f4[0]*f4[1]* (1/8*(35*(cos(theta[0]))^4
			- 30 *(cos(theta[1]))^2 + 3));

here is the whole code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>	
#include<cmath>
#include<string>
#include<fstream>

using namespace std;

//======================================================================


int main () 
{

//FILLING DATA ARRAYS 
// ask user for dat file
 
	start:
	cout << "Input filename where the raw data exist-->";
	char filename [50];
	ifstream dat;
	cin.getline(filename,50);
	dat.open(filename);

// if file isnt there report error 

	if (!dat.is_open()){
		cout << "File Does Not Exist!" << endl ;
	goto start;
	}

// read from file  and fill arrays 
	
	float theta[20], wthe[20], errwth[20];	
	int x = 0; 



	float a,b,c,d,e,f;

	while (! dat.eof()){

		dat >>  a >>  b >>  c;

		theta [x] = a ;
		wthe [x] = b;
		errwth [x] = c;
		cout << errwth[x] << endl;//check to see if filled right
		++x;
	}

// SECOND ARRAY FILLING 
// fill arrays for testing models 

	beg:
	cout << "Input filename where the data table exist-->";
	char file [50];
	ifstream table;
	cin.getline(file,50);
	table.open(file);

// if file isnt there report error 

	if (!table.is_open()){
		cout << "File Does Not Exist!" << endl ;
	goto beg;
	}

	x = 0 	;
	float ji [10], jm [10], jf[10], l1[10], l2[10] ;
	float f2[10] , f4[10] ;

	while (! table.eof()){

		table >>  a >>  b >>  c >> d >> e >> f;

		jf [x] = a;
		ji [x] = b;
		l1 [x] = c;
		l2 [x] = d;
		f2 [x] = e;
		f4 [x] = f;

		++x;
	}		
 
// testing calls not in a subroutine to check if calc is correct 
	float mwtheta ;
	mwtheta = 1 + f2[0]*f2[1]*(1/2*(*3* (cos(theta[0]))^2 *-1 )) 
			+ f4[0]*f4[1]* (1/8*(35*(cos(theta[0]))^4
			- 30 *(cos(theta[1]))^2 + 3));


	cout << mwtheta << endl;

return 0 ;
}
			

(*3* Should be (3* on the second line of code you have

WOW !! i have been staring at that for 15 mins and didn’t see it

not the error says «invalid operands of types ‘float’ and ‘float’ to binary ‘operator^’»

not sure what that means….

because you have ^ which is a binary operator I didn’t even realize that the first time. use pow( number , topowerof );

thanks

Topic archived. No new replies allowed.

я пытаюсь использовать вектор с указателем и модулями.
У меня есть эта проблема с C ++:
В main.cpp:

    #include<iostream>
using namespace std;
#include "Funcion1.hpp"
int main (int argc, char *argv[]) {
int vec[20];
int *punteroV = &vec[0];
for(int i = 0;i < 10;i++){
cout<<"Ingrese numero: ";
cin>>vec[i];
}
cout<<FUN(*punteroV) << endl;
return 0;
}

и в модуле:

#include "Funcion1.hpp"#include<iostream>
using namespace std;
int FUN(int &punteroV){

int num;
for(int i = 0;i<10;i++){
for(int j = 0;j<10;j++){
cout<<"i: "<<(punteroV+ i)<<endl<<"j: "<<(punteroV + j)<<endl;
if(*(punteroV + i) > *(punteroV + j)){
num = (punteroV + i);
}
}
}
return num;
}

и в модуле .hpp

   #ifndef FUNCION1_H
#define FUNCION1_H
int FUN(int&);
#endif

Компилятор выдает ошибку:

  error invalid type argument of unary '*' (have 'int')

Что означает эта ошибка?

-3

Решение

В функции FUN у вас есть эта строка:

   if(*(punteroV + i) > *(punteroV + j))

Вы пытаетесь сделать арифметику указателя на ссылку на целое число, а затем расценить его как int* Вы не можете сделать это прямо на ссылку. Чтобы сделать математику по ссылке, вы должны сначала взять ее адрес следующим образом:

   if(*(&punteroV + i) > *(&punteroV + j)){

0

Другие решения

Других решений пока нет …

Эта тема


  • Везде

  • Эта тема
  • Этот форум

  • Расширенный поиск

Поиск

Понравилась статья? Поделить с друзьями:
  • Error invalid transaction termination
  • Error invalid token error description token is incorrect перевод
  • Error invalid texture index 3ds max
  • Error invalid terms in product
  • Error invalid suffix x on integer constant