Looks like your function is fine, just one note, you should use '\"' the escape char for a " is \" Also I simplified the funct a bit. But, the prob with CreateFile() must be somewhere else. Are you sure you're using the modified string and not the original one when calling CreateFile? Also, if you want to create a local mirror of the directory structure, you'll need to replace the forward slashes with backslashes but in your prog use double backslashes which are actually the C++ escape char for a backslash:
http://www.example:80/files/text.txt
C:\\www.example:80\\files\\text.txt
Code:
#include<iostream.h>
int replaceillegalchars(char *string, char replace, char *output)
{
int len;
bool bFound = false;
len = strlen(string);
strcpy(output, string);
for(int z = 0; z < len; z++)
{
if(string[z] == '<' || string[z] == '>' || string[z] == ':' || string[z] == '*'
|| string[z] == '?' || string[z] == '\"' || string[z] == '|')
{
output[z] = replace;
bFound = true;
}
}
if(!bFound)return 0;
return 1;
}
void main()
{
char str[] = "http//:www.sub\"duck.com";
char buff[256];
replaceillegalchars(str, '_', buff);
cout<<buff;
cin.get();
}
Hope that helps
-Futura