Hopefully this is easy to do. I am writing a program in C that needs to run on Windows and Linux. On Linux it works great, but on Windows (through Cygwin) it screws up because the environment variables have backslashes rather than slashes in the path. Is there a way to replace these? I tried the following but it didn't change anything, probably because it thinks the backslash is escaping the next char which obviously isn't the case. Here's what I tried:
char* fixPath(char *env)
{
char *val[100];
strcpy(val, getenv(env));
int index = 0;
while(val[index])
{
if(val[index] == '\\')
val[index] = '/';
else
index++;
}
printf("\n***%s",val);
return val;
};
int main(int argc, char *argv[])
{
char *test1;
test1 = fixPath("SERVER1");
printf("\n*****%s",test1);
...
}
What is the right way to do this?