Hi. I'm having problems with an C exercise. So the exercise says: "Make a function with one variable (int k) which returns an array of the size of k where every box (sorry for my bad english) of the array is 1." So this is what I did.
Code:
#include <stdio.h>
#include <stdlib.h>
int pinakas(int k){
int i,c[i];
for(i=0;i<k;i++){
c[i]=1;
printf("%d",c[i]);
}
}
main(){
int a;
printf("Give integer: ");
scanf("%d",&a);
pinakas(a);
system("pause");
}
The program works, as long as I put 3 as an integer, if I put a number which is greater than 3 the program crashes. I could do the problem without an array (where instead of c[i] I would put c) and it works fine. So what am I doing wrong here? Thanks.