question on pointers....
| averageGuy (32) | |||||||||
i have defined my struct as:
then i did this:
everytime there is a (KElist+i) involved the will be an run time error. firstime just stops somewhere in xlocal
the the second time the code encounters the KElist+i further down the code: xiobase
saying some sort of corruption of heap..;.what can i do? | |||||||||
| firedraco (367) | |||
| What are you trying to create with coord *KElist...? Make an array of coords or something? | |||
| averageGuy (32) | |||
| yep! *KElist is an array of coords but i do not know how many variables are in there. (how many coords i have) the top part of the code reads as follows:
then after that is data manipulation and closing of files eg LOSFile.close(); | |||
| averageGuy (32) | |||
| i ran the program thru a console debug... and if i changed the (KElist+i) to (KElist+(i*k)) where k = sizeof (coord) it works. But got a problem in line 24. the data in my heightfile is like this: 103.749 1.36522 26 103.759 1.36661 125 103.769 1.368 37 103.779 1.36939 51 103.789 1.37078 42 103.799 1.37218 53 103.809 1.37357 42 103.819 1.37496 42 103.829 1.37635 37 103.839 1.37774 32 but after reading line6, the filepointer looks like it has stopped moving and i keep getting constant values and never the EOF bit. thus resulting in a infinite loop... im baffled.... I keep getting _long = 103.809 _lat = 1.00000 _height = 53 purpose of this code is to get the 1st line of data from HeightFile, den all the entries in the LOSFile and then the last entry from HeightFile... | |||
| bnbertha (404) | |||
I'm not sure how big the
new coord []; array would be without specifying the length, I've never tried it. I suspect your problem is something to do with this but I haven't quite got a handle on it yet.EDIT: I suspect you are going off the end, and overwriting something else. I think you need to do a linked list for this, or malloc/realloc or an STL container. | |||
| Zaita (1175) | |||
Agreed.
new coord[]; is not valid. Your not telling the OS how much memory to allocate. This is bound to cause a runtime error due to buffer-overflow.Have a look at the STL Vector container. e.g
You can store pointers in there
vector<coord*>; but you must de-allocate the memory from each pointer manually. | |||
This topic is archived - New replies not allowed.
