Написал код, вроде правильный,но вылезли ошибки от которых я не могу избавиться даже смотря ответы на зарубежных форумах. Вставил код целиком. Пишу в 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
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
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
|
|
here is the whole code
|
|
(*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
Другие решения
Других решений пока нет …
Эта тема
- Везде
-
- Эта тема
- Этот форум
-
- Расширенный поиск
Поиск