Я не могу понять, откуда происходит эта ошибка, но я предполагаю, что это как-то связано с выделением массивов / передачей массивов в качестве параметров. Извиняюсь, я новичок в C. Если бы кто-то мог помочь мне выяснить, откуда возникла эта ошибка, это было бы чрезвычайно полезно.
#include <stdio.h>
#include <stdlib.h>
void getSize(int *sizePtr) {
printf("Please enter the size of the class: ");
scanf("%i", sizePtr);
}
void allocateMemory(float *scoresPtr, int size) {
scoresPtr = malloc(size * (sizeof(float)));
}
void readScores(float *scores, int size) {
int i;
printf("Enter each score as a floating point value, each on a separate line, followed by enter: \n");
for (i = 0; i < size; i++) {
scanf("%f", &scores[i]);
}
}
void makeArrayCopy(float *original, float *copy, int size) {
int j;
for (j = 0; j < size; j++) {
copy[j] = original[j];
}
}
void findMin(float *scores, int size) {
int min = scores[0];
int i;
for (i = 1; i < size; i++) {
if (scores[i] < min) {
min = scores[i];
}
}
printf("%.1f", min);
}
void findMax(float *scores, int size) {
int max = scores[0];
int i;
for (i = 1; i < size; i++) {
if (scores[i] > max) {
max = scores[i];
}
}
printf("%.1f", max);
}
void findSum(float *scores, int size) {
int i;
int sum = 0;
for (i = 0; i < size; i++) {
sum += scores[i];
}
printf("%.1f", sum);
}
void findMean(float *scores, int size) {
int i;
double mean = 0;
for (i = 0; i < size; i++) {
mean += scores[i];
}
mean /= size;
mean = (float)mean;
printf("%.1f", mean);
}
void findMedian(float *sortedScores, int size) {
int mod = size % 2;
int sizeDivTwo = size / 2;
float median;
if (mod = 0) {
median = (sortedScores[sizeDivTwo] + sortedScores[sizeDivTwo + 1]) / 2;
} else {
median = sortedScores[sizeDivTwo + 1];
}
printf("%.1f", median);
}
void printAllScores(float *scores, int size) {
int i;
printf("%s", "Class Scores: \n");
for (i = 0; i < size; i++) {
printf("%.1f", scores[i]);
printf("%c", "\n");
}
}
void sortAscending(float *scores, int size) {
int i, j;
float temp;
for (i = 0; i < size; i++) {
for (j = 0; j < size - 1; j++) {
if (scores[j] > scores[j + 1]) {
temp = scores[j];
scores[j] = scores[j+1];
scores[j + 1] = temp;
}
}
}
}
int main() {
float scores;
int size;
float sortedCopy;
int op;
getSize(&size);
allocateMemory(&scores, size);
readScores(&scores, size);
allocateMemory(&sortedCopy, size);
makeArrayCopy(&scores, &sortedCopy, size);
sortAscending(&sortedCopy, size);
while (op != 0) {
printf("%s", "Please choose an option: \n 1: Calculate sum \n 2: Calculate mean \n 3: Calculate median \n 4: Find minimum score \n 5: Find maximum score \n 6: Print all scores \n 7: Print all scores in ascending order \n8: Exit");
scanf("%i", op);
switch(op) {
case 1:
findSum(&scores, size);
break;
case 2:
findMean(&scores, size);
break;
case 3:
findMedian(&sortedCopy, size);
break;
case 4:
findMin(&scores, size)
break;
case 5:
findMax(&scores, size);
break;
case 6:
printAllScores(&scores, size);
break;
case 7:
printAllScores(&sortedCopy, size);
break;
case 8:
op = 0;
break;
}
}
}