Returning Arrays/Pointers from a function
The problem is you're returning a pointer to something on the stack. You need to create your array on the heap, then free it when you're done:
int * splitString( char string[], int n )
{
int *newArray = malloc(sizeof(int) * n);
// CODE
return ( newArray );
}
int main( void )
{
int *x = splitString( string, n );
// use it
free(x);
return ( 0 );
}
Typically, you require the caller to pass in the result array.
void splitString( const char string[], int result[], int n) {
//....
}
This is advantageous because the caller can allocate that memory wherever they want.