gpt4 book ai didi

c - 我收到一条错误,指出 "warning: assignment makes integer from pointer wit hout a cast [enabled by default]"

转载 作者:行者123 更新时间:2023-11-30 17:42:49 27 4
gpt4 key购买 nike

我需要一些关于该错误的帮助,不知道如何解决它。我是编程新手,我正在使用 Sublime Text 编辑器和 Cygwin64。这在我老师给我们的讲座中起作用了,现在我想知道我的编译器设置是否正确?

 #include <stdio.h>
#define SIZE 15


//@todo: function that will return avg of values in array
float GetArrayAverage(int a[], int size);
//@todo: function that will return sum of values in array
int GetArraySum(int a[], int size);
//@todo: declare another function, one that multiplies all values by two

void DisplayArray(int a[], int size);
int GenerateRandomNumber(int UpperBound);

int main (void) {

//seed the random number generator
srand(time(NULL));

//declare an array
int array1[SIZE] = {0};


//populate the array
size_t i;

for(i = 0; i < SIZE; i++)
{
array1[i] = GenerateRandomNumber(i + 1);
}

DisplayArray(array1, SIZE);
printf("Array avg is: %f\n", GetArrayAverage(array1, SIZE) );
printf("Array sum is: %d\n", GetArraySum(array1, SIZE) );

} // End Main Function

/* Custom Functions */
int GetArraySum(int a[], int size)
{
size_t i;
int Total = 0;

for(i = 0; i < size; i++)
{
Total += a{i};
}
return Total;
}
float GetArrayAverage(int a[], int size)
{
size_t i;
int Total = 0;

for(i = 0; i < size; i++){
Total += a{i};
}
return (float)Total / size;


void DisplayArray(int a[], int size)
{
size_t i;

for(i = 0; i < size; i++){
printf("Element: %d - Value: %d\n", i, a[i]);
}
}

int GenerateRandomNumber(int UpperBound){
return (rand() % UpperBound);
}

最佳答案

您的代码中有许多语法错误,这是一个工作版本,请与您的代码进行比较。

#include <stdio.h>
#define SIZE 15


//@todo: function that will return avg of values in array
float GetArrayAverage(int a[], int size);
//@todo: function that will return sum of values in array
int GetArraySum(int a[], int size);
//@todo: declare another function, one that multiplies all values by two

void DisplayArray(int a[], int size);
int GenerateRandomNumber(int UpperBound);

int main (void) {

//seed the random number generator
srand(time(NULL));

//declare an array
int array1[SIZE] = {0};


//populate the array
size_t i;

for(i = 0; i < SIZE; i++)
{
array1[i] = GenerateRandomNumber(i + 1);
}

DisplayArray(array1, SIZE);
printf("Array avg is: %f\n", GetArrayAverage(array1, SIZE) );
printf("Array sum is: %d\n", GetArraySum(array1, SIZE) );

} // End Main Function

/* Custom Functions */
int GetArraySum(int a[], int size)
{
size_t i;
int Total = 0;

for(i = 0; i < size; i++)
{
Total += a[i];
}
return Total;
}
float GetArrayAverage(int a[], int size)
{
size_t i;
int Total = 0;

for(i = 0; i < size; i++)
{
Total += a[i];
}
return (float)Total / size;
}

void DisplayArray(int a[], int size)
{
size_t i;

for(i = 0; i < size; i++)
{
printf("Element: %d - Value: %d\n", i, a[i]);
}
}

int GenerateRandomNumber(int UpperBound)
{
return (rand() % UpperBound);
}

关于c - 我收到一条错误,指出 "warning: assignment makes integer from pointer wit hout a cast [enabled by default]",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20416696/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com