What should I do when there is an error because there is no file when opening fopen in read format?

Asked 2 years ago, Updated 2 years ago, 119 views

I'm doing my assignment. I want to start after I retrieve the data and variables that I had before I started. So we start fopen in read format first, then we move on to the menu window. But the problem is that the files are saved when the program exits, so if you don't run them once, there's no saved file. So I keep getting errors when I run it for the first time, what should I do?

file-io

2022-09-21 10:17

2 Answers

When you open a file with fopen, if the error code appears to be "no file", then you can initialize the variables right away on the memory and start.


2022-09-21 10:17

Check for files
File is present:
   Initialize data by reading previous data values
File does not exist:
   Initialize data with default data values


2022-09-21 10:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.