Click here to Skip to main content
16,015,973 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to get file record from file name? Pin
David Crow14-Jul-09 2:49
David Crow14-Jul-09 2:49 
QuestionSimple Button Styles Question Pin
Dave Kerr12-Jul-09 23:11
mentorDave Kerr12-Jul-09 23:11 
AnswerRe: Simple Button Styles Question Pin
josda100013-Jul-09 2:12
josda100013-Jul-09 2:12 
Questionstring format Pin
kumamako12-Jul-09 22:58
kumamako12-Jul-09 22:58 
AnswerRe: string format Pin
chandu00412-Jul-09 23:09
chandu00412-Jul-09 23:09 
AnswerRe: string format Pin
CPallini12-Jul-09 23:34
mveCPallini12-Jul-09 23:34 
QuestionRe: string format Pin
David Crow13-Jul-09 4:45
David Crow13-Jul-09 4:45 
Questionstd::search matches start of data before passing to function, but not within function? Pin
Mike the Red12-Jul-09 22:46
Mike the Red12-Jul-09 22:46 
#ifndef BYTE	// For OS X -ers
	#define unsigned char BYTE
	#define unsigned char * LPBYTE
#endif
#include <vector>
#include <algorithm>
void separate(vector< pair<LPBYTE, LPBYTE> >& retVec, LPBYTE data, LPBYTE delimeter, /* out */bool *bComplete = 0) {
	retVec.clear();
	if (bComplete) *bComplete = false;

	if (!data)	// No data - leave retVec empty
		return;

	LPBYTE dataEnd = data + sizeof(data);
	LPBYTE delEnd = delimeter + sizeof(delimeter);
	size_t delSize = distance(delimeter, delEnd);
	
	LPBYTE found = std::search(data, dataEnd, delimeter, delEnd);
	
	if (found == delEnd)	// Delimeter not in data - leave retVec empty
		return;

	cout << "In separate(...)\n";
	if (data[0] == delimeter[0])
		cout << "data[0] == delimeter[0]\n";
	
	if (found == data)
		cout << "Found == data.\n(" << found[0] << " == " << data[0] << ")\n";

	if (found != data)  			// Found delimeter ends first split
		cout << "Found != data; found == data[" << distance(data, found) << "].\n";
	return;
};
int main()
{
	BYTE buffer[] = {',', '1', '2', '3', ',', '4', '5', '6', ',', '7', '8', '9', ',', 0};
	BYTE del = ',';
	bool bComp = true;

	LPBYTE found = std::search(&buffer[0], &buffer[0] + sizeof(buffer), &del, &del + sizeof(del));
	if (found == &buffer[0])
		cout << "found == &buffer[0]\n";
	else
		cout << "found == &buffer[" << distance(&buffer[0], found) << "]\n";

	vector< pair<LPBYTE, LPBYTE> > lpb;
	separate(lpb, buffer, &del, &bComp);

	return 0;
}
Output:
found == &buffer[0]
In separate(...)
data[0] == delimeter[0]
Found != data; Found == data[4]


When I search from within main(), the leading comma is found, but once I pass the data & delimeter to separate(), it misses the leading comma and finds the next one.. obviously I'm missing something - can anyone spot what it is?

Your assistance is greatly appreciated!

MZR
AnswerFound it... Pin
Mike the Red12-Jul-09 23:24
Mike the Red12-Jul-09 23:24 
QuestionCFormView in CDockablePane Pin
eight12-Jul-09 22:44
eight12-Jul-09 22:44 
QuestionNeed a program that implements nearest neighbor method in c Pin
singh.vikas850812-Jul-09 21:55
singh.vikas850812-Jul-09 21:55 
AnswerRe: Need a program that implements nearest neighbor method in c Pin
Rajesh R Subramanian12-Jul-09 21:59
professionalRajesh R Subramanian12-Jul-09 21:59 
AnswerRe: Need a program that implements nearest neighbor method in c Pin
CPallini12-Jul-09 22:07
mveCPallini12-Jul-09 22:07 
GeneralRe: Need a program that implements nearest neighbor method in c Pin
Rajesh R Subramanian12-Jul-09 22:18
professionalRajesh R Subramanian12-Jul-09 22:18 
GeneralRe: Need a program that implements nearest neighbor method in c Pin
CPallini12-Jul-09 23:30
mveCPallini12-Jul-09 23:30 
GeneralRe: Need a program that implements nearest neighbor method in c Pin
Rajesh R Subramanian12-Jul-09 23:39
professionalRajesh R Subramanian12-Jul-09 23:39 
GeneralRe: Need a program that implements nearest neighbor method in c Pin
CPallini13-Jul-09 0:07
mveCPallini13-Jul-09 0:07 
GeneralRe: Need a program that implements nearest neighbor method in c Pin
Rajesh R Subramanian13-Jul-09 0:14
professionalRajesh R Subramanian13-Jul-09 0:14 
AnswerRe: Need a program that implements nearest neighbor method in c Pin
KarstenK12-Jul-09 22:24
mveKarstenK12-Jul-09 22:24 
QuestionHow to measure a Char width in a text Pin
susanne112-Jul-09 21:24
susanne112-Jul-09 21:24 
AnswerRe: How to measure a Char width in a text Pin
_AnsHUMAN_ 12-Jul-09 21:51
_AnsHUMAN_ 12-Jul-09 21:51 
AnswerRe: How to measure a Char width in a text Pin
Rajesh R Subramanian12-Jul-09 21:58
professionalRajesh R Subramanian12-Jul-09 21:58 
GeneralRe: How to measure a Char width in a text Pin
susanne112-Jul-09 22:01
susanne112-Jul-09 22:01 
GeneralRe: How to measure a Char width in a text Pin
Rajesh R Subramanian12-Jul-09 22:16
professionalRajesh R Subramanian12-Jul-09 22:16 
AnswerRe: How to measure a Char width in a text Pin
CPallini12-Jul-09 22:02
mveCPallini12-Jul-09 22:02 

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.