Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 727061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:31:27+00:00 2026-05-14T06:31:27+00:00

I’m writing to a text file using the following declaration: void create_out_file(char file_name[],long double

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:31:28+00:00Added an answer on May 14, 2026 at 6:31 am

    Use ‘const char file_name[]’ or ‘const char *file_name’ – you aren’t going to change the name in the function.

    Likewise, use ‘const long double *z1’ or ‘const long double z1[]’.

    The choice between pointer and array notation in a function prototype is largely arbitrary. I almost always use the pointer notation – because ultimately that is what is passed into the function. There are those who argue that if you are going to use the pointer as an array, use the array notation; it is a perfectly reasonable viewpoint – but not the one I use.

    Your code is more general if you pass the array size into the function:

    void create_out_file(const char *file_name, const long double *z1, size_t z_size)
    {
        ...
    }
    

    Note that the choice between pointer and array notation is not arbitrary for global variables. There is a lot of difference between these two:

    extern char *something;
    extern char  anotherthing[];
    

    One says there is a pointer-sized memory location that contains the address of a character string (presumably). The other says that there is a character string somewhere known by the name ‘anotherthing’, the value of which is a pointer. That may be a bit subtle – but the difference is crucial. The ‘pointer == array’ isomorphism only applies in function argument lists.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.