Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

In my C program, both opendir() and fopen() return NULL even though the directory and file are present.

+3 votes
asked Jun 8, 2023 by Jim Short (160 points)

That's it really. I open a command window and do a dir c:\code and the files are there. 

1 Answer

+1 vote
answered Jun 8, 2023 by Peter Minarik (86,640 points)

Yes, but those files are on your local PC, while the code you run on OnlineGDB runs on the server (Linux, mind you, not Windows). There's no C:\code directory there (there isn't even a C: drive on a Linux machine).

If you want to access a file in a code running on OnlineGDB, add that file to your project. There's an upload button left of the green RUN button.

In case the question is not in context of OnlineGDB and you are running the code on your local machine (not in OnlineGDB), please share your exact code that doesn't seem to work. (A guess here: maybe you did not escape your string properly? C:\code path escaped properly should look like "C:\\code" (notice the double backslashes)).

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...