Jump to content
  • Advertisement

Archived

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

Semicolon

strcpy problem

This topic is 5615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!