Advertisement

Creating Filenames from Callsigns

Started by August 06, 2000 12:05 PM
2 comments, last by Melo 24 years, 4 months ago
I have written a function that creates a filename from a Player-callsign, but it looks like it does not work Dunno why...

void CreatePlayerFilename (char* InputString, char* OutputString)
{
	BOOL Done = FALSE;
	char* InvalidChar = NULL;
	char* Filename = InputString;
	char* Filename2 = "";
	WIN32_FIND_DATA dFindData;
	BYTE n = 0;

	while (!Done)
	{
		Done = TRUE;

		InvalidChar = strpbrk (Filename, "/\?*""<>:|.");	// Check for invalid chars
		if (InvalidChar != NULL)
		{
			Done = FALSE;
			wsprintf (InvalidChar, "x");
			continue;
		}
		
		wsprintf (Filename2, "Players\\%s.mwp", Filename);

		if (FindFirstFile (Filename2, &dFindData) != INVALID_HANDLE_VALUE)
		{					// Check for existing files
			Done = FALSE;
			n++;
			wsprintf (Filename, "%s%d", Filename, n);
		}
	}
	OutputString = Filename2;
}
    
Can you give me suggestions, please. - - - - - - - - - - - - - - Andreas Mähler Wolf359 Interactive Edited by - Melo on 8/6/00 12:09:34 PM
You can''t just assign a char* to something after it''s been initialized I don''t think... What''s happening is you char* Filename2 is being assigned to nothing. Then when you try to call wsprintf() on it, the string is being written into unallocated memory, which is a bad thing.

Try making filename2 an array instead.
Advertisement
or you could use dynamic allocation and save a few bytes =)
a few bytes here and there makes a real big difrence....


Great Milenko

Words Of Wisdom:
"Never Stick A Pretzel In Your Butt It Might Break Off In There."


http://www.crosswinds.net/~milenko
http://www.crosswinds.net/~pirotech

The Great Milenko"Don't stick a pretzel up your ass, it might get stuck in there.""Computer Programming is findding the right wrench to hammer in the correct screw."
How can I do a dynamic allocation? I''ve never done it before...

- - - - - - - - - - - - - -
Andreas Mähler
Wolf359 Interactive

This topic is closed to new replies.

Advertisement