Archived

This topic is now archived and is closed to further replies.

Semicolon

strcpy problem

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites