【发布时间】:2018-02-26 03:45:00
【问题描述】:
我需要使用 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]);
}
}
【问题讨论】:
-
那是因为你没有给他们打电话?
-
void initialize_array(int list[], int size);不是调用,而是函数的声明。将其与您使用printf和scanf的方式进行比较。