Place functions in pointer variables

Asked 2 years ago, Updated 2 years ago, 53 views

file *fp;

fp = fopen("asd.txt", "w");

What is the point of substituting the fopen function, which functions to open asd.txt exclusively for writing, into the pointer variable?

c socket

2022-09-20 11:36

1 Answers

The fopen function collects information related to the file and generates the FILE structure type variable and returns the address value of the variable.

The FILE structure type variable cannot be created because it cannot collect information related to the file when opening the file fails, thus returning the NULL value.

file *fp; in the question is a typo in FILE *fp;. fp containing information related to an open file is called by various names such as file stream, open file, and FILE structural variable address value to read, write, or close other functions related to the file.


2022-09-20 11:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.