Hello. I am having trouble figuring out how to return the sum. I have 2 files p1.c and p2.c
p1.c contains my main which calls createAndCOunt like this:
printf("The value is %d\n",createAndCount());
p1.c also contains count which is called by createAndCOunt
count is:
int count (int* array)
{
int sum = 0;
int i;
for (i = 0; i < n-1; i++)
sum += array[i+1] - array[i];
return(sum);
}
p2 contains createAndCount (which I wrote but the p1.c was provided completed)
int createAndCount(int n)
{
int * intArray = calloc (n, sizeof (int));
int i;
for (i = 0; i < n; i++)
{
intArray[i] = rand() % 256;
}
return (int) count(*intArray);
}
The whole point of this exercise I believe is to have createAndCount initialize the array and fill it with Random integers and then return the sum from count.
Everything seems to work except for returning the sum from "count" and having createAndCount return that to main. What am I doing wrong by trying to return
"return (int count(*intArray));" from createAndCount????
PS I had it moved around before and the program asked for the integer of the size of the array and then I receive a SEGMENTATION FAULT?????
I am really new to C. Thanks. I will post full files if needed.