First day----fclose

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.