![]() |
|
#1
|
|||
|
|||
Help with const?Hello I have written an app like the one in my previous post only I am using a structure instead of parallel arrays and I have tried to implement the things I am learning here :-D I have a few errors like I had in the begining with the prev app. and I would like to address them here:
CPP / C++ / C Code:
And here are the errors reported by my visual c++ 6 compiler: Code:
the error refers to this "pplPtr *people[numPpl];" line. Why wont this work? I even tried to make numPpl a constant as you can see with the lines above it but that didnt work either? If I make numPpl a const global and assign a value to it no probs but I want the user to determin the numPpl! As allways any and all help is greatly appreciated! sincerely Jon |
|||
|
#2
|
||||
|
||||
|
You'll have to tell us where the errors are. With over 100 lines of code we can't tell what line error C2057: expected constant expression refers to. Place comments in the code pointing out the lines. And you might want to just post the code section (8-20 lines maybe) instead of 117 lines that don't have any bearing on the problem.
__________________
The 3 Laws of the Procrastination Society: 1) Never do today that which can be put off until tomorrow 2) Tomorrow never comes |
|
#3
|
||||
|
||||
|
I spoted this:
Quote:
I see you got the problem here: Quote:
But this wasn't the solution. The problem is that your compiler doesn't like the idea about reserving a static area of memory without knowing it's size. 'Cause it can't. Now if you gave a constant expression, like 5, he would have been OK with it. To accomplish this you need dynamic memory allocation. CPP / C++ / C Code:
Or to keep your model of pointer to pointer (although I'm not sure why you needed this in this context): CPP / C++ / C Code:
Here is a lame example: CPP / C++ / C Code:
You should read the C way and a more comprehensive explanation here. Also, if you will follow Walt's indication, you'll make it easy on us to provide you with faster and better help. Kind regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#4
|
|||
|
|||
|
Thanks for your help guys!!
Sorry for the delay I have had way too much on the go as of late! Hey walt, sorry I wont post the whole thing again but I did mention where the problem was in the post. I will coment the code from now on LuciWiz I think I am in over my head with the c++ let alone C lol. I figured I could let the user the input the number of structures required and its asociated memory with out any coding wizardry lol I think I will just use a const global for now untill I can wrap my sparse head around this stuff a little more Well I can get the code to compile now using a static but there is still somthing fishy going on with my mem usage it will prompt for the first name and then crash on enter? I think it is still somthing to do with my input routine? CPP / C++ / C Code:
Code:
Thanks for any and all help guys I know eventualy there will be an audible click in my head and I will see the big picture here Sincerely Jon |
|
#5
|
|||
|
|||
|
AHHA! I figured it out I had pointers in the srtructure
I also found a way that works better for me than that buffer was that I was using. I know there is no error control on the people->sex but I just didn't write any I was happy to finaly get it going Well here is the finished working code if any one other than me is learnig from this post is interested CPP / C++ / C Code:
Thanks every one for there help sincerely Jon |
Recent GIDBlog
Vista ?Widgets? on Windows XP by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| I need help implementing | kjc_13 | C++ Forum | 0 | 14-Feb-2005 16:00 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
| My program can run,but warning were display on Vc++ | fwongmc | C Programming Language | 5 | 08-Dec-2004 10:15 |
| Error: (function) undeclared -first use of this function | crystalattice | C++ Forum | 6 | 01-Nov-2004 04:36 |
| hashing help | saiz66 | C++ Forum | 1 | 06-Jul-2004 06:16 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The