i thought i would have a go at writing a function that moves a "space" ( a 0) down an array to a given index recursively rather than having to cal the function x number of times.
Code:
#include <stdio.h>
#include <stdlib.h>
void moveelements(int data[], int start, int end);
void printelements(const int x, const int data[]);
int main()
{
int data[6] = {2, 3, 4, 5, 6, 0}, num_elements = 6;
printelements(num_elements, data);
moveelements(data, 0, num_elements - 1);
printelements(num_elements, data);
return 0;
}
void moveelements(int data[], int start, int end)
{
int i = start;
if (i < end)
{
while (i + 1 != 0 && i < end)
{
i++;
}
data[i + 1]= data[i];
moveelements(data, start, i -1);
}
}
void printelements(const int x, const int data[])
{
int i;
for (i = 0; i < x; i++)
{
printf("%d ", data[x]);
}
}
it probably wont come as a surprise that i get a seg fault as soon as moveelements is called. so i am unable to debug it as i have no pointer to where the issue is(it fails on the openeing bracket of the function.
any advice
coop