As a reference this is the second part of my assignment:
int* generateFibonacci(int size);
This function will take as input an integer called size. The value contained in the size variable will represent how many numbers in the Fibonacci sequence to put into the array. The function will use
calloc
to create the array of this size and then fill the array withsize
numbers from the Fibonacci sequence, starting with1
and1
. When the array is complete the function will return a pointer to it.
My trouble come in play when I get the error in line 8 "warning: assignment makes and integer from pointer without a cast
".
Another error I get is in line 19 "warning: return makes pointer from integer without a cast
".
So my question is, how am I suppose to set up calloc
to make the array with a size from a user, then return a pointer to it?
#include <stdio.h>
#include <stdlib.h>
int* generateFibonacci(int size)
{
int i, array[size];
array[size]=(int*)calloc(size, sizeof(int));
array[0]=0;
array[1]=1;
for(i = 2; i < size+1; i++)
array[i] = array[i-2] + array[i-1];
return *array;
}
void printHistogram (int array[], int size)
{
int i, j;
for(i=0; i <= size; ++i)
{
for(j=0; j < array[i]; j++)
{
printf("*");
}
printf("\n");
}
}
int main(void)
{
int array[100], size;
printf("how big will your Fibionacci number be? ");
scanf("%i", &size);
generateFibonacci(size);
printHistogram(array, size);
return 0;
}