Click here to Skip to main content
15,894,907 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C question, can't free string from a struct Pin
John R. Shaw7-Sep-07 22:54
John R. Shaw7-Sep-07 22:54 
GeneralRe: small sample of where problem ocurres. Pin
gizmokaka7-Sep-07 22:34
gizmokaka7-Sep-07 22:34 
GeneralRe: small sample of where problem ocurres. Pin
John R. Shaw7-Sep-07 22:42
John R. Shaw7-Sep-07 22:42 
GeneralRe: small sample of where problem ocurres. Pin
markkuk7-Sep-07 23:12
markkuk7-Sep-07 23:12 
GeneralRe: small sample of where problem ocurres. Pin
gizmokaka7-Sep-07 23:21
gizmokaka7-Sep-07 23:21 
GeneralRe: small sample of where problem ocurres. Pin
John R. Shaw7-Sep-07 23:24
John R. Shaw7-Sep-07 23:24 
GeneralRe: small sample of where problem ocurres. Pin
Leslie Sanford7-Sep-07 23:42
Leslie Sanford7-Sep-07 23:42 
GeneralRe: Another qestion on the same subject. Pin
gizmokaka8-Sep-07 0:20
gizmokaka8-Sep-07 0:20 
Element = void*
I'm experiencing the same problem in a somewhat different situation
Here is the relevant code:

Element string_to_element(const char* val)
{
	Element localElem = malloc(sizeof(val));
	strcpy((char*)localElem , val);
	return localElem;
}

const char* element_to_string(Element e)
{
	int i;
	const char* localStr = (char*)malloc(sizeof(char)*(strlen((char*)e)+1));
	
	for (i = strlen(localStr) ; i > 0 ;i--)
		((char*)e)[i] = NULL;

	strcpy(localStr , (char*)e);
	return localStr;
}
void string_free_func(Element strElem)
{
	char* string;
	if(strElem == NULL)
        return;
	string = (char*)strElem;
	free(string); //error occurs 

}


void main()
{
	char* str2;
	char* str1 = "simple string";
	Element e1 , e2;
	
	e1 = string_to_element(str1);
	str2 = element_to_string(e1);
	
	string_free_func(e1);
}


This code is a bit modified but should illustrate the problem I'm facing.
any help would be most appreciate
GeneralRe: small sample of where problem ocurres. Pin
Russell'7-Sep-07 23:33
Russell'7-Sep-07 23:33 
QuestionClosing a view Pin
bob169727-Sep-07 11:08
bob169727-Sep-07 11:08 
AnswerRe: Closing a view Pin
Russell'7-Sep-07 23:02
Russell'7-Sep-07 23:02 
GeneralRe: Closing a view Pin
bob169728-Sep-07 4:44
bob169728-Sep-07 4:44 
GeneralRe: Closing a view Pin
Mark Salsbery8-Sep-07 7:04
Mark Salsbery8-Sep-07 7:04 
GeneralRe: Closing a view Pin
bob169728-Sep-07 9:14
bob169728-Sep-07 9:14 
GeneralRe: Closing a view Pin
Mark Salsbery8-Sep-07 10:51
Mark Salsbery8-Sep-07 10:51 
AnswerRe: Closing a view Pin
Nelek12-Sep-07 0:02
protectorNelek12-Sep-07 0:02 
Questiontree graph Pin
Chris Losinger7-Sep-07 10:48
professionalChris Losinger7-Sep-07 10:48 
AnswerRe: tree graph Pin
El Corazon7-Sep-07 11:25
El Corazon7-Sep-07 11:25 
AnswerRe: tree graph Pin
El Corazon7-Sep-07 11:32
El Corazon7-Sep-07 11:32 
QuestionMDI multiple view types - Window List Pin
bob169727-Sep-07 10:12
bob169727-Sep-07 10:12 
AnswerRe: MDI multiple view types - Window List Pin
bob169727-Sep-07 14:15
bob169727-Sep-07 14:15 
GeneralRe: MDI multiple view types - Window List Pin
bob169727-Sep-07 14:21
bob169727-Sep-07 14:21 
AnswerRe: MDI multiple view types - Window List Pin
Nelek12-Sep-07 0:08
protectorNelek12-Sep-07 0:08 
QuestionHow to prevent library/software cracking Pin
Hirakawa7-Sep-07 9:53
Hirakawa7-Sep-07 9:53 
AnswerRe: How to prevent library/software cracking Pin
David Crow7-Sep-07 10:16
David Crow7-Sep-07 10:16 

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.