I made some code to compare temperature of the week.
I made two functions, one to write to the array, other one is to calculate average temp. It compiles without errors. As soon as I enter my first number the app crashes and I get this error in the stdio.h lib :
Exception thrown at 0x533C742E (ucrtbased.dll) in 7.3.exe: 0xC0000005: Access violation writing location 0xCCCCCCCC.
I made a similar exercise without functions and it was working perfect. Hope you guys can help me out. Here is my code
#include <stdio.h>
#define MAX 7
#define _NO_CRT_STDIO_INLINE
void read(int);
float gem(int);
int main(void)
{
float x = 0;
int temp[MAX];
read(temp[MAX]);
x = gem(temp[MAX]);
printf("%f", x);
}
void read(int k[MAX])
{
for (int i = 1; i < 8; i++)
{
printf("geef de temp voor dag %d ", i);
scanf_s("%d%*c", &k[i-1]);
}
}
float gem(int y[MAX])
{
int som = 0;
float gem = 0;
for (int i = 0; i < 8; i++)
{
som += y[i - 1];
gem = som / 7;
return gem;
}
}