Skip to main content
gamedev.net
🔒 Locked

String searching problems...

Started by ATronic 4 replies 350+ views
Original Post
ATronic
ATronic
Hi All! I''ve been having a bit of a problem searching strings. Here''s what I''m trying to do. I have create a string like so: char *extensions; I then use an opengl function to get a list of all available extensions, seperated by spaces. extensions = (char*)glGetString(GL_EXTENSIONS); Now, I need to find out if the text "GL_ARB_multitexture" is in that string. I have tried the following meathods, all of which seem to crash for some reason. For all of the following, the result is an unhandled exception, and debugging always leads back to the search function. if(strstr(extensions, "ARB_multitexture") != NULL)) { do stuff; } and also using the following search function:
  
bool InStr(char *searchStr, char *str)
{
	char *extension;			// start of an extension in the list

	char *endOfStr;				// pointer to last string element

	int idx = 0;

	endOfStr = str + strlen(str);	// find the last character in str


	// loop while we haven''t reached the end of the string

	while (str < endOfStr)
	{
		// find where a space is located

		idx = strcspn(str, " ");

		// we found searchStr

		if ( (strlen(searchStr) == idx) && (strncmp(searchStr, str, idx) == 0))
		{
			return true;
		}

		// we didn''t find searchStr, move pointer to the next string to search

		str += (idx + 1);
	}

	return false;
}
  
Any help will be GREATLY appreciated. Oh yea, and I also tried the meathod that NeHe uses on his page... No luck... Thanks again! Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
Drazgal
Drazgal
Try this though I only tested it with "He llo" and searched for "ll" but give it a go. (Extentions the char holding all the extentions and pass "GL_ARB_multitexture" as ToFind)


  
bool SearchForString(char* Extentions, char* ToFind)
{
int Length = strlen(Extentions);
int TestLength = strlen(ToFind);

bool Found = false;

int Counter = 0;
char* Test = new char[TestLength + 1];

while(!Found && Counter < Length)
{
if(Extentions[Counter] == '' '')
{
memcpy(Test,&Extentions[Counter + 1],sizeof(char)*TestLength);
Test[TestLength] = ''\0'';

if(_strnicmp(Test,ToFind,TestLength) == 0)
{
Found = true;
}
}

Counter++;
}

return(Found);
}


Ballistic Programs
ATronic
ATronic
The good news is, your search function works! The bad news is, the opengl function glGetString(GLenum) is causing the memory problem. It just occurred to me that I should try feeding it a string of my own creation. So instead of using glGetString, I used the following:

char *extensions = "chocolate foo GL_ARB_multitexture bar";

and it worked! So then, on to figuring out how to solve the problem. Thanks for the search function, though!

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
sark
sark
An easier way, IMHO, to test for the existance of an opengl extension which you want to use is to call wglGetProcAddress() with the appropriate function name. If it returns NULL then its not supported.
ATronic
ATronic
I am using that, though I did not know that it would return NULL if it was not supported. Thanks, though!

Alex Broadwin
A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."
"The answer is out there."
"Please help, I''m using Windows!"
Alex BroadwinA-Tronic Software & Design-----"if you fail in life, you were destined to fail. If you suceed in life, call me.""The answer is out there.""Please help, I'm using Windows!"
shwig01
shwig01
I had the same problem with glGetString(), but just calling wglGetProcAddress works. The problem was glGetString(GL_EXTENSIONS) returning a null pointer. Does anyone know why this might happen?

[edit] I cant spell [/edit]

[edited by - shwig01 on August 3, 2002 11:24:35 PM]
-=bPhen=- , what a pity...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.