Click here to Skip to main content
15,896,154 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionmalloc ? Pin
_skidrow_vn_8-Aug-03 8:42
_skidrow_vn_8-Aug-03 8:42 
malloc ?


I want to allocate a memory block (such as 150 bytes) with all chars are initialize with "A"

this is my way:

char* p;
p=(char*)malloc(150)
//if( p == NULL )
// errhanlder("Insufficient memory available");
free(p);
// All okay but all chars are disorder, not "A"


but when I reset all chars in my string to "A" .....
ErrMessageBox is shown

char* p;
p=(char*)malloc(150)
//if( p == NULL )
// errhanlder("Insufficient memory available");
_strset('A'); // set all char to "A"
free(p); // Error in this line, if delete this line, it runs okay

Why when I try to free memory block, Error MessageBox show ?

>> when I debug , I get info:

// _msize(p) => return 150 but
// strlen(p) => return 154 ???????
// I try to set p+150 = 0x0(nullchar) but Error still show
// strcpy(p+150,0x0)

help me~

and is there a way to create StrArray[a][b] with a, b are variable
example :
StrArray[1][1] point to a string "hello"
StrArray[1][2] point to a string "bye"
StrArray[2][1] point to a string "good"
StrArray[2][2] point to a string "very long string ...."
........
thanks
AnswerRe: malloc ? Pin
Gary Kirkham8-Aug-03 8:56
Gary Kirkham8-Aug-03 8:56 
GeneralRe: malloc ? Pin
_skidrow_vn_8-Aug-03 9:03
_skidrow_vn_8-Aug-03 9:03 
GeneralRe: malloc ? Pin
David Crow8-Aug-03 9:33
David Crow8-Aug-03 9:33 
GeneralRe: malloc ? Pin
User 66588-Aug-03 9:44
User 66588-Aug-03 9:44 
GeneralRe: malloc ? Pin
Tim Smith8-Aug-03 13:10
Tim Smith8-Aug-03 13:10 
GeneralRe: malloc ? Pin
Gary Kirkham8-Aug-03 15:27
Gary Kirkham8-Aug-03 15:27 
AnswerRe: malloc ? Pin
Rick York8-Aug-03 12:38
mveRick York8-Aug-03 12:38 
GeneralVideo frame transmission Pin
Chikka8-Aug-03 8:39
Chikka8-Aug-03 8:39 
GeneralSave Changes to... screwing up in WinXP Pin
mcguile2578-Aug-03 8:31
mcguile2578-Aug-03 8:31 
GeneralRe: Save Changes to... screwing up in WinXP Pin
Neville Franks8-Aug-03 11:11
Neville Franks8-Aug-03 11:11 
GeneralRe: Save Changes to... screwing up in WinXP Pin
Joe Woodbury8-Aug-03 13:54
professionalJoe Woodbury8-Aug-03 13:54 
GeneralCreating a dialog when a user hits ctrl+g+d Pin
keegan8-Aug-03 8:25
keegan8-Aug-03 8:25 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
Maximilien8-Aug-03 8:47
Maximilien8-Aug-03 8:47 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
keegan8-Aug-03 9:00
keegan8-Aug-03 9:00 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
David Crow8-Aug-03 9:36
David Crow8-Aug-03 9:36 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
Richard Jones8-Aug-03 9:57
Richard Jones8-Aug-03 9:57 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
keegan8-Aug-03 10:04
keegan8-Aug-03 10:04 
GeneralRe: Creating a dialog when a user hits ctrl+g+d Pin
David Crow8-Aug-03 11:03
David Crow8-Aug-03 11:03 
GeneralClick and Double Click recognition Pin
Muhammad Basim8-Aug-03 8:00
sussMuhammad Basim8-Aug-03 8:00 
GeneralAdding bitmap to a CImageList object Pin
AJOsborne8-Aug-03 5:45
AJOsborne8-Aug-03 5:45 
GeneralA big problem while using jpeglib Pin
swandream8-Aug-03 5:15
swandream8-Aug-03 5:15 
GeneralRe: A big problem while using jpeglib Pin
JWood8-Aug-03 6:19
JWood8-Aug-03 6:19 
GeneralRe: A big problem while using jpeglib Pin
swandream8-Aug-03 15:54
swandream8-Aug-03 15:54 
GeneralOwner Drawn Menu Pin
ClickHeRe8-Aug-03 4:52
ClickHeRe8-Aug-03 4:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.