Я пытаюсь перетасовать набор массивов и распечатать их в порядке, но я получаю error: incompatible types when assigning to type 'int' from type 'IRIS'
, и я не могу его преодолеть.несовместимый тип в назначении
Я начинающий программист (только что изучил базовую C на прошлой неделе для экзамена по университету).
это мой код:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define MAX_SAMPLES 5
#define OUTPUT 3
typedef struct {
double sepal_lenght;
double sepal_width;
double petal_lenght;
double petal_width;
double out[OUTPUT];
}IRIS;
IRIS samples[MAX_SAMPLES] = {
{5.1,2.5,3.0,1.1,{0.0,1.0,0.0}},
{6.7,3.1,5.6,2.4,{1.0,0.0,0.0}},
{6.4,3.1,5.5,1.8,{1.0,0.0,0.0}},
{7.6,3.0,6.6,2.1,{1.0,0.0,0.0}},
{7.7,2.8,6.7,2.0,{1.0,0.0,0.0}},
};
main(){
int i, temp, randomIndex;
srand(time(NULL));
for (i=1; i < MAX_SAMPLES; i++) {
temp = samples[i];
randomIndex = rand() %MAX_SAMPLES;
samples[i] = samples[randomIndex];
samples[randomIndex] = temp;
}
for (i=0; i<MAX_SAMPLES; i++) {
printf("%d\n", samples[i]);
}
}
ошибка в строке: temp = samples[i];
любая помощь очень appriciated!
Вы назначьте 'int' к' IRIS', которые являются несовместимыми типами. Это все. – Downvoter
'temp' имеет тип' int'; 'samples [i]' имеет тип 'IRIS' –
' lenght' должен быть 'length' –