1

I have a very simple question that I'm sure can be answered quite easily, but google is not exactly yielding results that are helping rectify the error I am receiving.

I have a simple single-dimension array consisting of 100 integers. I am required to use another function to "fill" the array, so to speak.

While in main I am trying to make a simple call to the function that will "fill" the array with random integers.

However, I have written the call-to as such:

fillArray (int list[], int number);

With number being the # of random integers to store in the array. These parameters cannot change.

I keep receiving the error message:

"Expected '(' for function-style cast or type construction.

I have only been in my C++ class for 5 weeks now and I really have no idea what that means. I'm self taught for the most part in CSS, VBA, MySQL, and HTML of course. So I'm not as...intuitive when it comes to translating error messages.

Spent a while trying to google what exactly it meant and all the codes were way beyond my scope of understanding haha.

Here is my declaration of the function that I have within my main function (this is a requirement).

void fillArray(int, int);

And my function header:

void fillArray (int array[], int n)

I do not have anything written in the fillArray function as of yet. Could that be the reason for the error? If it is I will likely feel a bit foolish. :")

Kaitlyn
  • 129
  • 1
  • 2
  • 11
  • Post actual code. Preferably enough for us to attempt to compile and reproduce the error. Also, `void fillArray(int, int);` is clearly wrong, missing the `[]`. – David Schwartz Jul 07 '14 at 04:35
  • Thanks David, I fixed that per Tyler's note below!:) I have just started on this program so it is essentially empty! But I will post anyways. – Kaitlyn Jul 07 '14 at 04:43

2 Answers2

2

I think you just need to declare an array of integers as the first parameter:

void fillArray(int[], int);
Tyler Brock
  • 29,626
  • 15
  • 79
  • 79
  • That declares a pointer to an integer as the first parameter. – chris Jul 07 '14 at 04:33
  • Right a pointer to an integer that is the first in an array of integers. Either way... I think it's easier to conceptually understand it as an int[] rather than an int*. – Tyler Brock Jul 07 '14 at 04:37
  • Awesome, thanks!:D This textbook I am using is a bit skimpy on the real world examples haha. It's very useful when it comes to forcing you to learn but also a bit hard to get used to things without many valid examples. I have fixed my declaration! I am still receiving the same error message though. The error is triggered on the same line as my call to function. – Kaitlyn Jul 07 '14 at 04:41
  • I mean, the textbook is of such an old edition that it cost $0.01 on Amazon so yeah...:) I feel that the people on Stack Overflow probably have better diction when it comes to explaining anything coding related with an understandable train of thought. – Kaitlyn Jul 07 '14 at 04:43
  • 2
    @Katlyn - You won't learn modern (even correct) C++ if you're using an old or outdated textbook. What is the name of the book? – PaulMcKenzie Jul 07 '14 at 04:47
  • @Katlyn, *cough* http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – chris Jul 07 '14 at 04:49
0

You code should have the following structure:

void fillArray(int[], int);

int main()
{
    //...write code to create array here ...

    //this is how you call the function
    fillArray (list, number);   

}



void fillArray (int list[], int number)
{
    //...write your implementation of fillArray here
}
  • Haha, wow, thank you!:) My call to was wrong then, huh? At least after I fixed the declaration. Is it that you never include the data types in the call?? – Kaitlyn Jul 07 '14 at 04:49