简体   繁体   中英

Unable to execute a file in linux

I have created a program in which fopen() is being used. For Ex:-

int main() {
    FILE* check=NULL;
    check=fopen("C:\\Files\\open.txt","rb");
    if(check==NULL)
    {
        cout<<"Error";
    }
    else
    {
        //do something
    }
    
}

Now, in the above program windows path is working properly ie "C:\\\\Files\\\\open.txt" but when i try to execute the same program in wsl(linux) by changing the path to /mnt/c/Files/open.txt , I am getting error. I am not sure if setting up path this way is the standard procedure for fopen() in linux. Please suggest me something to overcome this error.

Try adding perror("fopen") to the main function and please share the output. It is difficult to answer this question without the output.

I think the problem may be: You don't have permission to access /mnt or no such file or that file doesn't have read permission... etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM