cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

Erase memory for ProMdlName

ms-6
6-Contributor

Erase memory for ProMdlName

Hi all,

 

I use code following code to create a Directory using toolkit

 

err = ProFileMdlnameParse(SelPath00, OutPutPath, MdlName, Ext, rev);
ProWstringToString(DwgName, MdlName);
mkdir(strcat("C:\\temp\\", DwgName))

 

When i run the application second time, the DwgName is getting appended.

(i.e first time DwgName is 1234, second time it becomes 12341234)

Kindly suggest.

3 REPLIES 3
zemanekp
13-Aquamarine
(To:ms-6)

Hi, probably  due to the improper use of strcat.

Function strcat has first parameter the pointer to resulting array (this pointer is also returned), second param is string to append.

For the first time you append string to the end of array which begin at some address, second time append next string to this array and so on ... (string array will overlap, exception occurred).

 

Try to refill the result string (strcpy), at least, e.g.:

 

char dir [PRO_PATH_SIZE];

strcpy(dir, "C:\\temp\\");

strcat(dir, DwgName);

 

Btw: You should not use strcat, try something like ProTKSnprintf

 

PZ

 

At least strcat_s(dir, PRO_PATH_SIZE, DwgName); so you get a crash at "out of allocated memory" and not write over other variables/allocated space inside your memory.

 

Br,

Eike

RPN
17-Peridot
17-Peridot
(To:ms-6)

You should init a char string

 

DwgName[0] = '\0';

 

before using.

Top Tags