Home c++ Pile was damaged

Pile was damaged

Author

Date

Category

When compiling issues an error
The exception is caused to 0x77C7F94D (ntdll.dll) in test2.exe: 0xc0000374: A bunch was damaged (parameters: 0x77CBB960).
Unprocessed exception at 0x77C7F94D (ntdll.dll) in test2.exe: 0xc0000374: A bunch was damaged (parameters: 0x77CBB960).
I understand that the error in the Strcat function, but I can not understand what

# include & lt; stdio.h & gt;
#Include & lt; String & GT;
#Include & lt; iostream & gt;
Using Namespace STD;
INT MAIN ()
{
  const char * path = "d: \\ sqlite \\";
  char oldname [] = "1.txt";
  Char newname [] = "2.txt";
  Const char * newpath = "D: \\";
  Char * Files = New Char [Strlen (Path) + Strlen (OldName) +1];
  Strcat (Files, Path);
  Strcat (Files, OldName);
  COUT & LT; & lt; files;
  Return 0;
}

Answer 1, Authority 100%

So, went. Do not compile, but perform.

char * files = new char [strlen (Path) + Strlen (oldName) +1];

No problem, the memory manager has allocated a place in memory and gave it to you. Of course, it is not clean (you did not say that it should be initialized?). And there lies, for example, something like

asdgysyh782qy6yr76786bxstgq748qs67576529187% * ^% $ @! VFGG & AMP;% & amp; T # @

Word trash. To which you add your row. We attribute it to the end. Which may be far beyond the allocated memory:

strcat (files, path);

Why don’t you copy first part of a new line?

strcpy (files, path);

Question is not rhetorical – I really wonder, really there, where did you know about Strcat (on lectures, from the book …) Nothing was said first about STRCPY ?

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions