invalid types 'char[int]' for array subscript

Jun 4, 2013 at 5:54pm
Hello all,

So I was continuing my little text based adventure game, and I ran into a pinch.
The code has gotten too big to post here, so here's the link to the codepad. http://codepad.org/1eUjSi5z

I ran that into codepad, and now I got an error like so:

In function 'int main()':
Line 52: error: invalid types 'char[int]' for array subscript
compilation terminated due to -Wfatal-errors.



Any ideas?
Jun 4, 2013 at 6:02pm
You defined heshecaps as a single character. So you may not use the subscript operator with this variable.

char heshecaps;
Jun 4, 2013 at 6:02pm
Jun 4, 2013 at 6:05pm
You need to declare heshecaps as a pointer or an array, right now line 11 you declared it as a single char so you don't have an array to access on lines 52-53.
Jun 5, 2013 at 5:29pm
http://codepad.org/8GDUvyK2

I made some touch-ups, how about now?
Jun 5, 2013 at 5:43pm
Firstly this comparison is incorrect from the logical point of view. It will be always equal to true because expression "girl" is not equal to zero.
if (gender == "woman" || "girl")

I think you meant

if (gender == "woman" || gender == "girl")

Also arrays have no the assignment operator. So the code below is invalid.

{heshe = "she";
heshecaps = "She";}

Instead you should use standard C function strcpy
Last edited on Jun 5, 2013 at 5:45pm
Topic archived. No new replies allowed.