![]() |
|
#1
|
|||
|
|||
Problem with structure arraysI'm having problems adding values to a structure in an array:
CPP / C++ / C Code:
From everything I read this seems to be the correct way to store a value. I recieve the following error upon trying to compile: syntax error before '.' token Am I doing it incorrectly? Thank you for your time. |
|
#2
|
|||
|
|||
|
Can you post more of your code, please.
Because the only problem I can think of is that maybe your line "area[1].aid = 1001;" is someplace such in your overall code that it is out of the visibility range of the declaration of the area array. Just speculating of course. Because to me it seems that there is nothing wrong from what is visible in your posting so maybe it is something that is not visible. |
|
#3
|
|||
|
|||
|
Here is the full code I have thuse far. Pretty ashamed of it really as I'm still quite the novice and its no where near anything functional.
CPP / C++ / C Code:
It's something I'm adding to as I learn new things. I'm scratching my head over this. I'm not quite sure what exactly you meant about out of the visibility range. |
|
#4
|
|||
|
|||
|
It must be done inside a function or a constructor (which is basically a function too). Move the line in main( ) and you'll be fine.
|
|
#5
|
|||
|
|||
|
Quote:
Along that vein it worked, thanks a lot. Though trying to assign string values doesn't seem to work. CPP / C++ / C Code:
That results in: incompatible types in assignment Just not my day. Obviously I'm doing something wrong, I just don't see it. Maybe I shouldn't mess with structures just yet. |
|
#6
|
|||
|
|||
|
You must use strcpy( ) which is used as follow: strcpy(destination, source); A better alternative, though, is strncpy( ). It also takes the size of the buffer in parameters. It will protect you from buffer overflow. strncpy(destination, source, size);
|
|
#7
|
||||
|
||||
|
Quote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#8
|
|||
|
|||
|
Then you could modify it a little bit by making your own.
CPP / C++ / C Code:
|
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Airport Log program using 3D linked List : problem reading from file | batrsau | C Programming Language | 11 | 29-Feb-2008 08:44 |
| Repetition structure problem and question | brookeville | C++ Forum | 17 | 29-Oct-2004 18:48 |
| problem with arrays | melas | C Programming Language | 5 | 12-Oct-2004 05:18 |
| [CONTEST?]Data Structure Test | dsmith | C Programming Language | 2 | 06-Jun-2004 16:13 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The