What's wrong with my Array of Structs Function?

Hello,

I'm trying to create an array of structs, and to output the data, but I'm getting a whole bunch of errors that say that I have stray numbers (i.e. Error: stray \342 in the program, Error: stray \200 in the program, etc."). I'm getting about 25-30 of these strange errors.

Would appreciate the input!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

struct ABC{
    unsigned n;
    char c;
    double a[3];
};

void show( const ABC & x ){

cout << "{" << x.n << ", ";
cout<< "\'" << x.c << "\', {";

for (int i = 0; i < 3; i++){
if (i == 2){
cout << x.a[i] << "";
break;
}
cout << x.a[i] << ", ";
}
cout << "}}";

}

void show( const ABC arr[], unsigned elements ){

for (int i = 0; i < elements; i++){

show(arr[i]) << endl;

}
}

int main (){

ABC structArr[4] = {

{123, ‘A’, {1.1, 1.2, 1.3}},
{234, ‘B’, {2.1, 2.2, 2.3}},
{345, ‘C’, {3.1, 3.2, 3.3}},
{456, ‘D’, {4.1, 4.2, 4.3}}

};

show(structArr, 4);

return 0;
}
Look on line 37-40 and such; the quotes around your characters are 'smart quotes', not the standard ASCII ones that the compiler wants to see.
Thank you.

The last issue that I seem to be having is on line 28...I have a problem when I pass each element of the array of struct into my function that outputs every element. I get the following error (below), and am not sure why. I understand that you should usually do something like arr[i].n << arr[i].c, etc. when you're iterating through a loop on an array of structs, but I believe this should have been already done in the function that i'm calling.

error: invalid operands of types ‘void’ and ‘<unresolved overloaded function type>’ to binary ‘operator<<’|
Last edited on
Ok, I got it fixed now...Removed the "<< endl;" from line 28, and am now good to go.
Topic archived. No new replies allowed.