I'm having some problem with my code, it crashes when I enter the value of n.
I have entered what I think the code should do.
I guess there is an issue with the pointer to *a[i] which cause the program to crash.
#include <stdio.h>
#include <stdlib.h>
void assign_zero(int * a[], int * n){ // fetches value of a and n
int i;
for (i = 0; i < *n; i++)
*(a)[i] = 0; // puts every value in the array to 0 (a[3] = {0,0,0,0})
}
int main(){
int n;
printf("Choose value of n: ");
scanf("%i", &n); // stores the int at n's adress
int a[n]; // sets the length of the array
assign_zero(&a, &n); // sends the adress of a and n to assign_zero
int x;
for (x = 0; x < n; x++)
printf("%i", a[x]); // prints 00000... depending of n's value
return 0;
}
assign_zerois of the wrong type.