Print a value to a file?

Hello,

I have this code:

BioAPI_FAR FARRequest=0;
BioAPI_BOOL bFARPrecedence=0;
BioAPI_INPUT_BIR inputProcessed;
BioAPI_FAR FARAchieved;
inputProcessed.Form = BioAPI_BIR_HANDLE_INPUT;
inputProcessed.InputBIR.BIRinBSP = &hProcessdBIR;

bioReturn = BioAPI_VerifyMatch(g_ModuleHandle,
&FARRequest,
NULL,
&bFARPrecedence,
&inputProcessed,
&g_inputStoredBir,
NULL,
&bResult,
&FARAchieved,
NULL,
NULL);


How can I print &FARAchieved to a file?
Or, printing the whole bioReturn would be fine too.

Thanks a lot!
What is a FARAchieved?
It is "A 32-bit integer value (N)"
If it's an integral type, just open the file and write it.
I tried this:

long int myFAR = *FARAchieved;
FILE *out = fopen( "FARoutput.txt", "w" );
if( out != NULL )
fprintf( out, "%d\n", myFAR );

And it gives me error, how could I print the value of &FARAchieved?


Would this code also create the file?

Thanks for the help!
FARAchieved is already an integer, right? So just remove the * and write only FARAchieved.

 
fprintf( out, "%d\n", FARAchieved );


And be sure to close your file after writing (fclose). ;)


Ciao, Imi.
Hello,
thanks for the reply. I will get a chance to test it tomorrow (when I get to the machine this app is for).
I have a few questions:
1) will fprintf automatically create the file, or do I need to create it beforehand, and if it is created automatically, where will that file be saved?
2) If I run the program for example three times, will I have 3 records in the same file or will it just overwrite?

Thanks!
Since you specified "w" as second parameter to fopen, your file will be:

- created if not present
- overwriten every time without any questions

You can use "a" to append to an existing file. See here for more: http://www.cplusplus.com/reference/clibrary/cstdio/fopen/

The file is created relative to the directory from which you started the application. If you have a favourite place to put it, you can put this as absolute path into your code: fopen("C:\\Data\\FARoutput.txt", "w"). (Some people hate hard-coded paths like this in source code, so prepare for a battle with your local code reviewer.. ;)

Ciao, Imi.
If you're new to files, you may as well start with the C++ iostream library.
1
2
3
4
#include <fstream>
//...
std::ofstream os("C:\\Data\\FARoutput.txt");
os << FARAchieved << std::endl;

Last edited on
Topic archived. No new replies allowed.