I want to write a function that returns a part of another array. Here's how I tried to implement it:
char *subarrayWithRange(char *array, int location, int length)
{
char subarray[length];
subarray = (array + location);
return subarray;
}
When I try to compile it, clang
gives me this error:
error: array type 'char [length]' is not assignable
Apparently, I can't assign an array to a sub-array of another array. But, this works when I define the subarray as a pointer:
char *subarrayWithRange(char *array, int location, int length)
{
char *subarray;
subarray = (array + location);
return subarray;
}
Now, though, I can't define the length of the subarray. Is this a C language thing? Can I get around this somehow?