strcpy problem
Hey Guys!
I have a problem with the strcpy function in c++. Here''s the code:
struct container
{
...
char sName[30];
...
};
...
container* inst;
inst = new container[0];
strcpy(container[0].sName, "anything");
...
on runtime there''s no problem, but when the programm closes I get uncaught exeptions. The problem occurs also with the sprintf func. It seems like its connected with the sName member of the container struct. If I call none of these string copy funcs, no exeption occurs.
here''s the given line:
HEAP[Halfcolt.exe]: Heap block at 00B40848 modified at 00B40874 past requested size of 24
help would be great!
thank''s in advance
inst = new container[0];
should be
inst = new container[1];
arrays are zero-indexed (the first one''s index is zero), but you still have to creat the proper number when allocating them.
Sorry for this stupid question!(i knew it before) But thank you very much. Some problems you don''t see when only 1 person looks!
Thank you very much!
Thank you very much!
use std::vector and this problem goes away (all of its many facets)
[edited by - Magmai Kai Holmlor on August 5, 2003 7:34:29 PM]
[edited by - Magmai Kai Holmlor on August 5, 2003 7:34:29 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement