-
dumb text game :P
Code:
my structure:
void opendrawer(void);
struct itemgot
{
char notepad[];
};
my not working part of my program:
void opendrawer(void)
{ /*line 83*/
struct itemgot items;
cout << "You opened the drawer. There is a notepad inside, which you take out" << endl;
items.notepad=1;/*Line 86*/
}
errors: Parse error before '{' token on line 82
items undeclared on 86
-
When your instantiating an object in C++ (struct/class), you don't need the word struct/class.
Line 84 should be somethin' like this:
itemgot items; // No 'struct'
That should take care of the second error. I can't figure out the first one from the given code though. Usually when you get those "Parse error before ..." messages, your error is actually a few lines up, and is something along the lines of a missing comma or semi-colon.
Also, you might want to give 'notepad' a starting size. i.e.:
char notepad[20];
The last line probably does not do what you want it to either. It is trying to assign the pointer 'notepad' to memory address 1. Chances are you want something like strcpy(notepad, "1").
-
Oh yeah, thanks. I forgot that arrays are pointers :P