LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

File Error

Hi everybody,

 

I have a problem, I tried to do a file to save some parameters from Network Analyzer (R&S ZNB8) to my computer.

However, I have this error :

 

"NON-FATAL RUN-TIME ERROR:   "Test1.c", line 370, col 34, thread id 0x0000125C:   Library function error (return value == 0 [0x0]). (ENOENT) No such file or directory"

 

I tried a lot of new code to delete this error but I didn't success.

Somebody know how to delete this error?

 

"FILE* testsauvegarde = NULL;

testsauvegarde = fopen("testsauvegarde.txt", "r+");
return 0;"

 

My error comes from red part.

0 Kudos
Message 1 of 19
(4,442 Views)

It is maybe not a problem of your code - the file you specify does not exist...

Or maybe it exists but not in the current directory, so it is better to specify the full path name, not just the file name

...and if the file does not exist and you want to create a new file, you should specify another mode, e.g., 'w+' instead of 'r+'

0 Kudos
Message 2 of 19
(4,441 Views)

Thank you Wolfgang!

How can I specify the full path name while in fopen function you need to specify only the file name ?

I created the file before run the code, so I think it's not necessary to write "w+" mode, no?

Thank you again!

0 Kudos
Message 3 of 19
(4,437 Views)

If the file exists you do not need to create it, so 'r+' is fine.

 

There are several ways of how to obtain a path name, you can do it manually ("C:\\My Documents\\my filename.txt") or using, e.g., a file popup, or the function MakePathname (); the latter two methods take care about the backslashes, in the first you have to remember to replace single backslashes by double backslashes.

 

0 Kudos
Message 4 of 19
(4,436 Views)

By using the function "MakePathname ("Z:\\.....", "testsauvegarde.txt", pathname);" I have always the same problem...

0 Kudos
Message 5 of 19
(4,430 Views)

What do you mean by 'the same problem'?

 

You should have something like

 

file_name [ MAX_PATHNAME_LEN ] = ""; 

 

MakePathname ( "c:\\", "myfile.txt", &file_name );

 

or   

 

GetProjectDir ( &path_name );

MakePathname ( path_name, "myfile.txt", &file_name );

 

and then

 

fopen ( file_name, "r+" );

0 Kudos
Message 6 of 19
(4,426 Views)

This is the same error that "No such file or directory".

I tried the second way :

GetProjectDir ( &path_name );

MakePathname ( path_name, "testsauvegarde.txt", &testsauvegarde );

testsauvegarde=fopen("testsauvegarde.txt", "r+");

0 Kudos
Message 7 of 19
(4,424 Views)

oh... Smiley Surprised what is the purpose of calling MakePathname in your case - you do not use the generated path name... have a look at the differences between your code and mine...

0 Kudos
Message 8 of 19
(4,422 Views)

The purpose is to do understand to the computer that I have to save parameters on this file with the path that I gave...

What was your purpose?

0 Kudos
Message 9 of 19
(4,425 Views)

ok, to put it more clearly, in your case the call to MakePathname is useless because you do not make use of the result.

 

The result of

int MakePathname (char directoryName[], char fileName[], char pathname[]);

is the character array pathname, which you happen to call testsauvegarde; however, in the next line you use the constant "testsauvegarde.txt".

 

You should have written fopen ( testsauvegarde, "r+' );

0 Kudos
Message 10 of 19
(4,423 Views)