LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Opening a binary file without it's name

Solved!
Go to solution

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);
             }

0 Kudos
Message 1 of 4
(989 Views)
Solution
Accepted by topic author dreaming.kitsune

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+"); 

S. Eren BALCI
IMESTEK
Message 2 of 4
(954 Views)

Thank you very much! Now it's working. 
I didn't know that "path" is variable for file's name.

0 Kudos
Message 3 of 4
(927 Views)

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 😉 )

S. Eren BALCI
IMESTEK
0 Kudos
Message 4 of 4
(924 Views)