c - Creating a Custom Array Size with Random Numbers -
i trying write function returns array of custom size , populated random numbers. whole code such:
#include <stdio.h> #include <stdlib.h> #include <time.h> int check_error(int a); void initialize_array(int array[],int a); void print_array(int array[],int a); int replace(int array[],int i, int b, int c); int main(void) { int asize, array; printf("hello!\nplease enter size of array:\n"); scanf("%d", &asize); check_error(asize); while (check_error(asize)==0) { printf("invalid input! enter size of imput size again:\n"); scanf("%d", &asize); } if (check_error(asize)==1) { initialize_array(array, asize); } } int check_error(int a) { if (a> 0 && <= 100) return 1; else return 0; } void initialize_array(int array[], int a) { int i; srand(time(null)); for(i=0; < a; i++) { array[i]=rand()%10; } }
specifically need getting initialize_array
work intended.
in code, remove previous definition of array , this:
if (check_error(asize)==1) { int array[asize]; initialize_array(array, asize); // other stuff here }
note array valid between { }'s of if(check_error) statement.
Comments
Post a Comment