You are using the concept of global variables here. They are initialized to 0, So you can use it like this.
You are correct in this case except if you change buf[2000]
to buf[1000]
then you have to make some changes like this :
for (int i = 0 ; i < 1000; i++) {// change i<2000 to i<1000 otherwise you may get a segmentation fault error
a[i] = new_str[i];
}
And yes, while dealing with passing arrays to a function you have to pass its size as described in other answers .:)
NOTE-- You are not initializing array with the ini
function , You are actually assigning values to the array buf
, and this answer is according to that. If you want to initialize the array then other answers are according well enough , otherwise make one more change if you are mistaken with initialization to assignment .
Comment in your main i.e,
ini(buf);// assign buf
My answer is according to that , if that is what you want to do :)