06-21-2016 02:54 AM
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.
06-21-2016 03:37 AM - edited 06-21-2016 03:42 AM
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+'
06-21-2016 03:48 AM
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!
06-21-2016 04:00 AM
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.
06-21-2016 05:10 AM
By using the function "MakePathname ("Z:\\.....", "testsauvegarde.txt", pathname);" I have always the same problem...
06-21-2016 05:28 AM
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+" );
06-21-2016 05:34 AM
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+");
06-21-2016 05:38 AM
oh... 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...
06-21-2016 05:47 AM
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?
06-21-2016 05:55 AM
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+' );