Im trying to write a program that breaks down a large array into smaller arrays. For the example i'm posting, I made a 4int array to be brokend into 2 2-int arrays.
Whenever I run my function to fill the two arrays, it always fills the first array just fine, but then rewrites the first array with the second two integers instead of storing them in the second array.
Why is the fill_array function not using the address of the second array?
Code:
#include <stdio.h>
void fill_ary(int ary_s[], int ary_d[], int cnt);
void print_small_ary(int sary[]);
int main(void){
setbuf(stdout, NULL);
int original_ary[4] = {1,2,3,4};
int small_ary_a[2] = {0};
int small_ary_b[2] = {0};
fill_ary(original_ary, small_ary_a, 0);
fill_ary(original_ary, small_ary_b, 2);
print_small_ary(small_ary_a);
print_small_ary(small_ary_b);
}
void fill_ary(int ary_s[], int ary_d[], int cnt){
int i;
for(i = cnt;i<cnt+2;i++)
ary_d[i] = ary_s[i];
}
void print_small_ary(int sary[]){
int i;
i = 0;
for(i=0;i<2;i++)
printf(" %i", sary[i]);
printf("\n");
return;
}
Output:
3 4
0 0