Jay Khandkar Jay Khandkar - 3 months ago 8
C Question

What can I pass to fopen?

Can I pass a character array to

fopen
? For example:

fopen(s, "r");


Where
s
is declared as a character array and is null terminated.

Answer

s must be a null terminated character array.enter image description here

The man pages confirm this

FILE *fopen(const char *path, const char *mode);

You can see that it must be null terminated, since no size argument is given.