OK so I'm trying to parse simple URL's from a whole char chunk using strtok but always keeps giving me an unhandled exception error . SO here is all the code in C++ :

char* str = "(%/\%)google.com(%/\%)hotmail.com(%/\%)nananna.org(%/\%)"
	char *url[];
	while(str != NULL){
		url[0] = strtok(str, "(%/\%)");
		    if (DownloadFile_1(url[0],szPath) == 0);{// Writes "URL 1"
			ExitProcess(0); 
		   }
		url[1] = strtok (NULL, "(%/\%)");
		   if (DownloadFile_1(url[1],szPath) == 0);{// Writes "URL 2"
			ExitProcess(0); 
		   }
		url[2] = strtok (NULL, "(%/\%)");
		   if (DownloadFile_1(url[2],szPath) == 0);{// Writes "URL 3"
			ExitProcess(0); 
		   }
	}

EDIT** : str can only be a const or char* because the function that I'm using with it uses const char.

Edited 5 Years Ago by Warl30ck: n/a

strtok modifies the source string. You have no choice but to make a copy if the original string can't be modified. It also looks like you need to study about arrays a bit.

Edited 5 Years Ago by Narue: n/a

strtok modifies the source string. You have no choice but to make a copy if the original string can't be modified. It also looks like you need to study about arrays a bit.

OK, and yeah I shortly began C++ and sincerely I found nothing that says it modified the variable str {original}, all I found was that it was unsafe :/

Edited 5 Years Ago by Warl30ck: n/a

all I found was that it was unsafe :/

"Unsafe" is often a code word for "I don't understand how to use it correctly". Off the top of my head, I can only think of one function in the standard library that's legitimately unsafe, and it's not strtok. ;)

That doesn't look very C++ish to me, specifically because you're using a C function.

And the C++ version of strtok is...wait for it...strtok. Or manually parsing the string yourself. Or using a third party library that does it for you.

Edited 5 Years Ago by Narue: n/a

This question has already been answered. Start a new discussion instead.