Hi, I'm writing to a text file using the following declaration:
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);
}
Where z1 is an long double array of length ARRAY_SIZE. The calling function is:
create_out_file("E:/first67/jz1.txt", z1);
I defined the prototype as:
void create_out_file(char file_name[], long double z1[]);
which I'm putting before "int main" but after the preprocessor directives. My code works fine.
I was thinking of putting the prototype as
void create_out_file(char file_name[],long double *z1).
Is this correct? *z1
will point to the first array element of z1
.
Is my declaration and prototype good programming practice?
Thanks a lot...
Update: To make the program general, I defined ARRAY_SiZE as:
const int ARRAY_SIZE = 11;
The prototype becomes:
void create_out_file(const char *file_name, const long double *z1, size_t z_size)
the called function is:
create_out_file("/tmp/myname", z1, ARRAY_SIZE);
and in the function declaration I have
void create_out_file(const char *file_name, const long double *z1, size_t z_size)
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 < z_size; i++)
fprintf(out, "%.16Le\n", z1[i]);
fclose(out);
}
Will this work?
New Update On compilation, for the line
for(i = 0; i < z_size; i++)
in the declaration, I get the warning: : warning C4018: '<' : signed/unsigned mismatch
What's wrong here?
Thanks...
Latest news: It's working fine thanks to Jonathan Leffler