Fourth day-----file location function and buffer refresh function

Source: Internet
Author: User

/*
Function: Set file offset location
Parameter 1:file Flow
Parameter 2: Offset

Parameter 3: Offset position: Seek_set, seek_cur, seek_end
Return value: Returns 0 successfully, otherwise returns 1 and sets errno
*/intlongint whence);
/*
Function: Determine the location of the file location pointer
Parameter 1:file Flow
return value: The current position of the file location pointer, otherwise return-1, and set errno*/ long ftell (FILE *stream); /*
Function: File location pointer definition to file start location
Parameter 1:file Flow
return value: None
*/void Rewind (FILE *stream);

The program for determining file size using the Fseek function and the Ftell function:

#include <stdio.h>#include<stdlib.h>intMainintARGC,Char**argv) {FILE*FP; if(ARGC <2) {fprintf (stderr,"usage....\n"); Exit (1); } FP= fopen (argv[1],"R"); if(fp = =NULL) {Perror ("fopen ()"); Exit (1); } fseek (FP,0, Seek_end); printf ("%ld\n", Ftell (FP)); Exit (0);}

Using the fseek function to produce an empty file

/*  Function: Refreshes a stream
Parameter 1:file stream, if null, refreshes all stream
*/ int fflush (FILE *stream);

Buffer function: Merging system calls

Line buffer: Refresh when line breaks, full time brush, Force refresh (stdout)

Full buffer: Full time brush, Force refresh (default, except stdout)

Unbuffered: Content that needs to be output immediately (stderr)

To set the buffering mode:

int Char int mode, size_t size);

Fourth day-----file location function and buffer refresh function

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.