/* nag_open_file (x04acc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * NAG C Library * * Mark 8, 2005. * */ #include #include #include #include #include int main(void) { Integer mode, exit_status = 0; NagError fail; Nag_FileID fileid; const char *filename; char line[100], line2[100]; INIT_FAIL(fail); Vprintf("nag_open_file (x04acc) Example Program Results\n"); Vprintf("\n"); filename = "x04acc_example.txt"; Vprintf("Attempting to write to and read from file %s:\n", filename); /* Open the file for writing */ mode = 1; /* nag_open_file (x04acc). * Open unit number for reading, writing or appending, and * associate unit with named file */ nag_open_file(filename, mode, &fileid, &fail); /* Write a line to the file we opened */ sprintf(line,"%s", "NAG nag_open_file (x04acc) example program"); /* nag_write_line (x04bac). * Write formatted record to external file */ nag_write_line(fileid, line); /* Close the file */ /* nag_close_file (x04adc). * Close file associated with given unit number */ nag_close_file(fileid, &fail); /* Open the file for reading */ mode = 0; /* nag_open_file (x04acc), see above. */ nag_open_file(filename, mode, &fileid, &fail); /* Read the line back from the file */ /* nag_read_line (x04bbc). * Read formatted record from external file */ nag_read_line(fileid, line2, 100, &fail); if (!strcmp(line, line2)) printf(" - correctly wrote line \"%s\" to file and read it back.\n", line); else { printf(" - failed to write line \"%s\" to file and read it back.\n", line); exit_status = 1; } return exit_status; }