Skip to main content
gamedev.net
🔒 Locked

strcpy problem

Started by Semicolon 2 replies 400+ views
Original Post
Semicolon
Semicolon
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
krez
krez
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.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
Semicolon
Semicolon
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!
Shannon Barber
Shannon Barber
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]
The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.