I have been learning C as of late, and the one thing that keeps tricking me up is file reading/writing. My goal is to print out the contents of "words.txt" in my main file. I know how to do so when the words and main file are in the same folder, but not when they are in seperate folders as shown here. How do I do I read the file in this setting?SS of my file set up as example
I want to read the words.txt and print it out, in it's entirety, using C.
Firstly, it doesn't matter where your
main.cfile is, only thing that matters is where you run the executable.If your
words.txtis fromC:\Users\user\directoryyou can access it:words.txtfromC:\Users\user\directorydirectory/words.txtfromC:\Users\user../words.txtfromC:\Users\user\directory\srcC:\Users\user\directory\words.txtfrom anywhereIf you will be running the program only from VSCode, you can use
Words Folder/words.txt, as VSCode executes commands from the base directory (so it's whereWords FolderandMain Folderis).But a more robust solution would be to specify the full path.