Click here to Skip to main content
15,912,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionshow dialog Pin
prathuraj3-Mar-07 21:49
prathuraj3-Mar-07 21:49 
AnswerRe: show dialog Pin
Ravi Bhavnani3-Mar-07 22:42
professionalRavi Bhavnani3-Mar-07 22:42 
AnswerRe: show dialog Pin
toxcct4-Mar-07 8:45
toxcct4-Mar-07 8:45 
Questionrealloc function problem Pin
Ayman Mashal3-Mar-07 18:41
Ayman Mashal3-Mar-07 18:41 
AnswerRe: realloc function problem Pin
blue_rabbit3-Mar-07 20:19
blue_rabbit3-Mar-07 20:19 
GeneralRe: realloc function problem Pin
Ayman Mashal3-Mar-07 21:06
Ayman Mashal3-Mar-07 21:06 
GeneralRe: realloc function problem [modified] Pin
blue_rabbit3-Mar-07 21:12
blue_rabbit3-Mar-07 21:12 
GeneralRe: realloc function problem [modified] Pin
Ayman Mashal3-Mar-07 21:53
Ayman Mashal3-Mar-07 21:53 
the array is created by adding characters using the following function


void Append(char **buffer,int size,char c)<br />
{<br />
	<br />
	(*buffer)=(char *)realloc(*buffer,(size+1) * sizeof(char));<br />
	(*buffer)[size-1]=c;<br />
	(*buffer)[size]='\0';<br />
}


after the array is created i am running the function that raise the error several times and its work fine and i increase and decrease its content using the following function :

void replaceStr(char **replaceIn,char *replaceWith,int fromIndx,int toIndx)<br />
{<br />
	<br />
	char *ptr=(*replaceIn)+fromIndx;<br />
	int replaceWithLen=(replaceWith==NULL)?0:strlen(replaceWith);<br />
	int replacedStrLen=toIndx-fromIndx;<br />
	int originalStrLen=strlen(*replaceIn);<br />
	//int str3Len=strlen(str3);<br />
	int shift=replaceWithLen-replacedStrLen;<br />
	int bytesToMove=strlen(ptr)+1;<br />
	int originalLength;<br />
<br />
	printf("%s\n",*replaceIn);<br />
	if(replaceWithLen==0)<br />
	{<br />
		memmove(ptr-1,ptr+replacedStrLen,bytesToMove);<br />
	<br />
	}<br />
	else<br />
	{<br />
		if(replaceWithLen>replacedStrLen)<br />
		{<br />
			originalLength=strlen(*replaceIn);<br />
	<big>(*replaceIn)=(char *)realloc(*replaceIn,(originalLength+shift+1) * sizeof(char));</big><br />
			if(*replaceIn==NULL)<br />
				printf("Error while allocating memory");<br />
			*((*replaceIn)+originalStrLen)='\0';<br />
			ptr=(*replaceIn)+fromIndx;<br />
			memmove(ptr+replaceWithLen,ptr+replacedStrLen,bytesToMove);<br />
		}<br />
		else<br />
			memmove(ptr+replaceWithLen,ptr+replacedStrLen,bytesToMove);<br />
	<br />
	}<br />
<br />
	memcpy(ptr,replaceWith,replaceWithLen);<br />
<br />
}


the error happen at some point in the line in bold !





-- modified at 4:21 Sunday 4th March, 2007
GeneralRe: realloc function problem [modified] Pin
blue_rabbit3-Mar-07 23:36
blue_rabbit3-Mar-07 23:36 
QuestionRe: realloc function problem Pin
prasad_som3-Mar-07 20:29
prasad_som3-Mar-07 20:29 
AnswerRe: realloc function problem Pin
Ayman Mashal3-Mar-07 22:43
Ayman Mashal3-Mar-07 22:43 
QuestionCalculator Project Pin
Charles Covington3-Mar-07 12:50
Charles Covington3-Mar-07 12:50 
AnswerRe: Calculator Project Pin
prasad_som3-Mar-07 17:53
prasad_som3-Mar-07 17:53 
AnswerRe: Calculator Project Pin
Newbie004-Mar-07 0:52
Newbie004-Mar-07 0:52 
Questionfast way 2 adjust contrast??? Pin
samreengr83-Mar-07 11:18
samreengr83-Mar-07 11:18 
QuestionRe: fast way 2 adjust contrast??? Pin
Mark Salsbery5-Mar-07 7:00
Mark Salsbery5-Mar-07 7:00 
AnswerRe: fast way 2 adjust contrast??? Pin
Rilhas5-Mar-07 13:38
Rilhas5-Mar-07 13:38 
Questionhow do i connect to SQl SERVER WHIT vc++.NET? Pin
Ehsan_aminian3-Mar-07 11:10
Ehsan_aminian3-Mar-07 11:10 
AnswerRe: how do i connect to SQl SERVER WHIT vc++.NET? Pin
Hamid_RT4-Mar-07 5:18
Hamid_RT4-Mar-07 5:18 
QuestionOpinions solicited - naming of access methods... Pin
charlieg3-Mar-07 7:47
charlieg3-Mar-07 7:47 
AnswerRe: Opinions solicited - naming of access methods... Pin
Maximilien3-Mar-07 10:39
Maximilien3-Mar-07 10:39 
QuestionMenu management on dialog based project Pin
ilgale3-Mar-07 6:27
ilgale3-Mar-07 6:27 
AnswerRe: Menu management on dialog based project Pin
Tony Hill3-Mar-07 9:14
professionalTony Hill3-Mar-07 9:14 
QuestionBest Book? Pin
Dirso3-Mar-07 5:20
Dirso3-Mar-07 5:20 
AnswerRe: Best Book? Pin
Rajesh R Subramanian5-Mar-07 23:54
professionalRajesh R Subramanian5-Mar-07 23:54 

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.