fopen / fopen_s and writing to files

Posted by yCalleecharan on Stack Overflow See other posts from Stack Overflow or by yCalleecharan
Published on 2010-04-04T16:48:49Z Indexed on 2010/04/04 16:53 UTC
Read the original article Hit count: 209

Filed under:
|
|
|

Hi, I'm using fopen in C to write the output to a text file. The function declaration is (where ARRAY_SIZE has been defined earlier):

void create_out_file(char file_name[],long double *z1){
FILE *out;
int i;

if((out = fopen(file_name, "w+")) == NULL){
fprintf(stderr, "*> Open error on output file %s", file_name);
exit(-1);
}

for(i = 0; i < ARRAY_SIZE; i++)  
fprintf(out, "%.16Le\n", z1[i]);  
fclose(out);  

}

My questions:

  1. On compilation with MVS2008 I get the warning: warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. I haven't see much information on fopen_s so that I can change my code. Any suggestions?

  2. Can one instruct fprintf to write at desired precision? If I'm using long double then I assume that my answers are good till 15 digits after the decimal point. Am I right?

Thanks a lot...

© Stack Overflow or respective owner

Related posts about fopen

Related posts about precision