03-06-2021 06:34 PM - edited 03-06-2021 06:46 PM
Hi, I have to write code which will open selected binary file. I don't know how to open selected file without writing it's name in a code. Does anyone have any idea how this code shoul look like?
Part of a code responsible for selecting a file and opening it:
switch (event)
{
case EVENT_COMMIT:
status = FileSelectPopup ("", "*.cps", "", "Pick a file", VAL_LOAD_BUTTON, 0, 1, 1, 0, path);
if(status==1)
{
FILE *f; //(Opening a binary file to read)
f=fopen ("","rb+");
if(!f)
{
perror("f");
exit(1);
}
Solved! Go to Solution.
03-06-2021 09:19 PM
Hi,
I couldn't quite get what you mean by "without its name".
You already have the full file path (which includes the file name) in your path variable.
You can pass it to the fopen function as the first parameter:
f=fopen (path,"rb+");
03-07-2021 04:57 AM
Thank you very much! Now it's working.
I didn't know that "path" is variable for file's name.
03-07-2021 05:10 AM
That's OK.
This is the main purpose of the FileSelectPopup. It lets you select a file and gives you its path.
Otherwise it would be useless...
( Note: Do not hesitate to give kudos if my reply helped you 😉 )