Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I got very strange problem with my C++ code.
One section my code connect to specific page of one website and read one number(for example number 45814). My code working good with all servers but recently I got problem with specific server. When read number from this page shows number "458140" instead "45814". I mean it adds one zero to number. my code is as below:

C++
char* __stdcall Get_Account_Number_FromWEB()
{
	
		
	std::string strTopic = "get account from web";
	//!!!! this is to be replaced with our request	
	const char * szPlimusRef = gpVar->m_strPlimusRef.c_str();
	std::string strHttpReq = "http://www.example.com/1.htm"; // sample page
	
	HINTERNET webHANDLE =  InternetOpen(strTopic.c_str(), 0, "0", "0", 0);
	HINTERNET webResult = InternetOpenUrlA(webHANDLE, strHttpReq.c_str(), "0", 0, -2080374528, 0);
	if ( webResult )
	{
		char szwebBuffer[1024];
		memset(szwebBuffer,0,sizeof(szwebBuffer));
		DWORD dwBytes = sizeof(szwebBuffer);
		DWORD dwBytesActual = 0;
		BOOL bRead = InternetReadFile(webResult, szwebBuffer, dwBytes, &dwBytesActual);
		InternetCloseHandle(webResult);			
		
		gpVar->m_strWEBDigest = (char*)szwebBuffer;
	}
	else
	{
		gpVar->m_strWEBDigest = "No internet connection";
	}
	InternetCloseHandle(webHANDLE);	
	
	return (char*)gpVar->m_strWEBDigest.c_str();
	
	
} 


When open this page manually I see "45814" but when this function read that shows "458140".

I checked this with different server all works correctly but only one server got this strange problem.
Can anybody solve this problem?
Regards,
Posted
Updated 16-Aug-11 2:56am
v3

1 solution

Check the bytes readen (dwBytesActual) and terminate the string:
szwebBuffer[dwBytesActual]=0;

Regards.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900