Why am I only able to manipulate files with pointers?

Asked

Viewed 59 times

2

In the statement I always have to put

FILE *Arq;

If I put it without the * it presents an error. Why?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site

1 answer

4

Because the given that function fopen() returns is a pointer, so you have to declare the variable with a compatible type. If it returns something else, this is what you have to declare in the variable that will sustain the object that will handle the file manipulation. See the documentation.

I could question why it returns pointer. It is a complex object and it has information in an area outside the stack, even managed by the operating system, then access indirectly is the only option.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.