Function "read()" forces the program to exit when typing information into dynamically allocated array

Solution 1:

The code presented has at least these major problems:

  1. If you #include <stdio.h> then you may not define FILE as an ordinary identifier, including a typedef name. Doing so violates a language constraint, so a conforming compiler is obligated to emit a diagnostic about that. If it accepts the code then the resulting behavior is undefined.

  2. Given that u.s has type int, the call

        scanf("\n%d", u.s);
    

    is wrong and produces undefined behavior. The intended function call appears to have been

        scanf("\n%d", &u.s);
    

    There is a better than average probability that the UB attending this mistake would manifest as a program crash. Some C compilers would have diagnosed this error for you, so if yours did not (you are compiling this locally for testing purposes, right?) then you should consider getting a better compiler.

  3. The function call read_file(pn+i); is incorrect because function read_file() does not accept any arguments. Even a pretty poor C compiler ought to have issued a diagnostic about that, so either you are not paying attention to the compiler's diagnostic messages or you are in desperate need of a better compiler. Typically, however, the UB associated with an error of this kind does not manifest as a program crash, and might not have a perceivable manifestation at all.

There is also this lesser issue:

  1. The program ignores the return value of read_file(). This is allowed, but it is not what you appear to want do. The result is that the data that are read are not written to the object to which your pn pointer points. The program output should give evidence of this.