gpt4 book ai didi

C-Void 函数不会执行

转载 作者:行者123 更新时间:2023-11-30 18:34:56 24 4
gpt4 key购买 nike

我需要使用 0 到 50 之间的输入来打印数组中的一组随机数,以确定要打印多少个随机整数。一切似乎都正常,但 void 函数似乎没有执行,使数组全部为 0 值。

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

int check_error();
void initialize_array();
void print_array();

int main(void){
int list[50]; //initializing arrays
int size,error; //initializing size

printf("Enter the size of an input");
scanf("%d",&size);
error = check_error(size);
while(error == 0){
printf("Invalid input enter the size of the input: ");
scanf("%d",&size);
error = check_error(size);
}
void initialize_array(int list[], int size);

printf("%d",list[2]);

void print_array(int list[], int size);

printf("\n\nDONE %d",list[0]);

return 0;
}


int check_error(int input){
if(input < 1 || input > 50)
return 0;
else
return 1;
}

void initialize_array(int list[],int listSize){
int i;
for(i=0;i<=listSize;++i){
list[i] = (rand()%10);
}
}


void print_array(int array1[],int arraySize){
int i;
for(i=0;i<=arraySize;++i){
printf("%d, ",array1[i]);
}
}

最佳答案

您没有正确调用该函数。按照您的方式,您只是提供函数的声明,而不是实际调用它们。 您想像打电话一样调用他们

error = check_error(size);

除了 void 函数之外,没有返回值可存储在变量中。 改变

void initialize_array(int list[], int size);

initialize_array(list, size);

void print_array(int list[], int size);

print_array(list, size);

关于C-Void 函数不会执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48981137/

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