I'm trying to make a directory using _mkdir()
but it keeps giving me an "invalid parameter" error. It does work if I hard-code the path. I'm receiving the name of a desktop through a socket.
This is my code:
char getinfo[CMP_SIZE] = "getinfo";
for (unsigned int i = 0; i < master.fd_count; i++)
{
char infoPath[1000];
s = master.fd_array[i];
if (s != ListenSocket)
{
int r = sendStrBuffer(s, getinfo, CMP_SIZE);
if (r == SOCKET_ERROR)
{
printf("error\n");
}
char *whoami = recvStrBuffer(s);
// output: desktop-00hlt29\name
for (int i = 0; whoami[i] != '\0'; i++) {
if (whoami[i] == '\\') {
whoami[i] = '_';
}
}
printf("whoami: %s\n", whoami); // output: desktop-00hlt29_name
sprintf(infoPath, "C:\\Users\\name\\Desktop\\%s", whoami);
//strcat_s(infoPath, whoami);
printf("infoPath: %s\n", infoPath); //output: C:\\Users\\name\\Desktop\\desktop-00hlt29_name
if (_mkdir(infoPath) == -1) // It works if I do like this: _mkdir("C:\\Users\\name\\Desktop\\desktop-00hlt29_name")
{
printf("Failed to create directory: %s\n", strerror(errno)); // output: Failed to create directory: Invalid argument
}
else
{
printf("Directory created successfully\n");
}
}
}