I've been over this all day and it looks fine to me. Yet it is crashing my program, so I know there's an error here. I'm fairly certain the error exists in the getvalue function

int main ()
{
	char thevalue[1024];
	char needle[25];
	char  haystack[2048]; 

	memset(thevalue,0,sizeof(thevalue)-1);
	memset(needle,0,sizeof(needle)-1);
	memset(haystack,0,sizeof(haystack)-1);
	strcpy_s(haystack, 2048,"Attached: True\r\nMode: Auto\r\nProfile: C:\\Games\\easymoney\\file.xml\r\nLog: None\r\nHealth: 1\r\nMana: 1794 (87%)\r\nName: Appledore\r\nClass: Warlock\r\nLevel: 36\r\nExperience: 42231\r\nNext-Experience: 58700\r\nXP/Hour: 13068\r\nLocation: 371.77 -71.77\r\nHeading: 3.64964509010315\r\nKLD: 33/32/0\r\nTarget-Name: Mountain Yeti\r\nTarget-Level: 33\r\nTarget-Health: 0.92\r\nTarget-FactionID: 16\r\nTarget-Mana: 0\r\nTarget-Location: 366.06 -75.03");

	strcpy_s(needle,25,"Mana: ");
	getvalue(thevalue,haystack,needle);
	printf("value '%s'\n***************\n",thevalue);
	return 0;
}
//find needle in haystack.  Copy from end needle to end of line from haystack into thevalue
int getvalue(char * thevalue, char * haystack, char * needle)
{
 char * pch;
 char temp[2048];
 int templength=0;

 memset (temp,0,sizeof(temp));
//find the needle in the haystack
 pch = strstr (haystack,needle);
 if(!pch)
 {
	return(0);
 }
//copy whats after the needle into temp
 strcpy_s(temp,sizeof(temp)-1,pch+strlen(needle));

//now copy just the line into thevalue and return
 pch = strstr (temp,"\r");
 if(!pch)
 {
	return(0);
 }
 templength = strlen(temp)-strlen(pch);
 strncpy_s(thevalue,sizeof(thevalue)-1,temp,templength);
 return (1);
}

Recommended Answers

All 2 Replies

>> strncpy_s(thevalue,sizeof(thevalue)-1,temp,templength);
theValue is a pointer, so sizeof(theValue) is the size of a pointer which is 4 on all 32-bit compilers.

yup. that was it. you rock sir :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.