http://blog.csdn.net/qin9r3y/article/details/8652207
/* Learn about the C language storage */
The previous section fopen the return value of the FILE * Type pointer is placed on the heap
If the return value of a function is a pointer and has an inverse operation, then the pointer to the return value must be on the heap
If the return value of a function is a pointer without an inverse operation, then the pointer to the return value may be on the heap or in the static area
int fclose (FILE *FP);
Parameters: Flow
Return value: Success 0, failed EOF defaults to-1.
#include <stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>intMainvoid) {FILE*FP; FP= fopen ("Temp","w+"); if(fp = =NULL) { //fprintf (stderr, "fopen () failed. errno =%d\n ", errno); //perror ("fopen ()");fprintf (stderr,"fopen ():%s\n", Strerror (errno)); Exit (1); } printf ("ok!"); Fclose (FP); Exit (0);}
View Code
Run Result: Successfully created file and print OK.
To view the file permissions created:
-rw-rw-r--: 0666 & ~umask (0002);//purpose in order to produce files that are too loose
There is an upper limit to the flow resources used by the test
#include <stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>intMainvoid) {FILE*FP; intcount; while(1) {FP= fopen ("Temp","w+"); if(fp = =NULL) { //fprintf (stderr, "fopen () failed. errno =%d\n ", errno);Perror ("fopen ()"); Break ; }} printf ("count =%d\n", Count); Exit (0);}
To view the results of the output:
1021
Command: ULIMIT-A View---Open files 1021+stdin+stderr+stdout ==1024
First day----fclose