_mkdir 无效参数 C

问题描述 投票:0回答:1

我正在尝试使用

_mkdir()
创建一个目录,但它一直给我一个“无效参数”错误。如果我对路径进行硬编码,它确实有效。我正在通过套接字接收桌面名称。

这是我的代码:

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);

        for (int i = 0; whoami[i] != '\0'; i++) {
            if (whoami[i] == '\\') {
                whoami[i] = '_';
            }
        }

        printf("whoami: %s\n", whoami);
        sprintf(infoPath, "C:\\Users\\%username%\\Desktop\\%s", whoami);
        //strcat_s(infoPath, whoami);
        printf("infoPath: %s\n", infoPath);
                            
        if (_mkdir(infoPath) == -1) 
        {
            printf("Failed to create directory: %s\n", strerror(errno)); // print the error message
        }
        else 
        {
            printf("Directory created successfully\n");
        }
    }
}
c winapi mkdir
1个回答
1
投票

至少这个问题

不匹配的说明符

// sprintf(infoPath, "C:\\Users\\%username%\\Desktop\\%s", whoami);
sprintf(infoPath, "C:\\Users\\%%username%%\\Desktop\\%s", whoami);
© www.soinside.com 2019 - 2024. All rights reserved.