hi guys, i'm having this problem: i want to create a function that receives an array, then it generates a random and then returns the array with the first element of the array being the generated random and the previous values are appended to the end of the array.
i've searched a bit on the net and found this solution to return arrays:
create a typedef of the array an then return the typedef.
but i'm getting some errors.
this is what i have:
randomizer.h
#pragma once
#include <math.h>
typedef int array_mod[1023];
int rand(void);
array_mod randomizer(int array[]);
randomizer.c
#include "randomizer.h"
array_mod randomizer(int array[])
{
//the array size that is received as an argument is [1023]
int random = rand();
int array2[random];
int i=0;
int j=0;
//copy the first elements to a new array
for (i = 0; i != random; i++)
{
array2[i] = array[i];
}
//shifting the elements of the first array to the left
for (i = 0; i != 1023-random; i++)
{
array[i]=array[random];
}
//add the elements that were copied in the first for()
for(i=1023-random; i!=1023;i++){
array[i]=array2[j];
j++;
}
//copy the modified array into the typedef and return it
array_mod signal = array;
return signal;
}
the error i get is : Illegal return type 'array_mod'.
another question i have for you guys is how to do what i need, i.e. having a number ( for instance 5) and then append the first 5 elements of the array to the end, being that the array will then start with the index [5] element.
is my code ok for that or is there an easier\efficient way of doing it?
thanks in advance for any help.
Rui