Hi BPoyner,
Are you sure that your file path in OpenFile or fopen is correct, as in you are specifying a path that exists and with the proper escape characters for backslashes (e.g. "C:\\Windows\\myfile.txt")? Are you using the access modes correctly and are you sure that the OS file system permissions are set correctly for the particular file/directory you are writing too?
Here is an example you can try that just creates a new file with fopen, writes to it with fprintf, closes it with fclose, reopens it with OpenFile, reads it with ScanFile, and closes it again with CloseFile that you can use to assure yourself that the functions work properly. I have tested it and it works fine. (note: the only reason I mixed all of these function calls is so that you can
see the different families of functions work) Just give this code a try and let us know how it turns out.
#include
#include
#include
static int hmyfile2;
static FILE *hmyfile;
int main (int argc, char *argv[])
{
int numitemsformatted;
char buffer[100];
int status;
int numchars;
fopen ("myfile.txt", "w+");
hmyfile = fopen ("myfile.txt", "w+");
numchars = fprintf (hmyfile, "%s", "Hello World!");
status = fclose (hmyfile);
hmyfile2 = OpenFile ("myfile.txt", VAL_READ_ONLY, VAL_OPEN_AS_IS,
VAL_ASCII);
numitemsformatted = ScanFile (hmyfile2, "%s>%s[t0]", buffer);
status = CloseFile (hmyfile2);
numitemsformatted = FmtOut ("%s", buffer);
getchar();
return 0;
}
Jason F.
Applications Engineer
National Instruments
www.ni.com/ask