The difference between fread and fgets:

Source: Internet
Author: User
Tags fread
fread and fgets the difference between:Fread: Computes the length in byte bits, reads the data at the specified length and number, stops after it encounters the end or completes the specified length read.
Fgets: Full row reads, encounters carriage return or end stop. Used in text mode. The function of the Fgets function is to read a string from a specified file into an array of characters, in the form of a function call: fgets (character array name, n, file pointer), where n is a positive integer. Indicates that a string read from a file does not exceed n-1 characters. After the last character read, add the string end Sign '/0 '. For example: Fgets (STR,N,FP) is meant to read n-1 characters into the character array str from the file referred to in FP. (read by row)
Fread is a read-write function for the entire block of data that can be used to read and write a set of data, such as an array element, the value of a struct variable, and so on. Read Block function calls in general form: Fread (BUFFER,SIZE,COUNT,FP), where buffer is a pointer, in the Fread function, it represents the first address of the input data. The size represents the number of bytes in the data block. Count represents the number of blocks of data blocks to read and write. FP represents a file pointer.
For example:
Fread (FA,4,5,FP); The significance of this is that from the file referred to in FP, 4 bytes (a real number) are fed into the FA of the real group each time, reading 5 consecutive times, i.e. reading 5 real numbers into the FA. The handbook says:
Fputs
Fputs--alias of Fwrite ()
Description
This function is an alias for Fwrite ().

Fgets
(PHP 3, PHP 4)
Fgets--read a row from the file pointer
Description
string fgets (int handle [, int length])
Reads a row from the file pointed to by handle and returns a string with a maximum length of length-1 bytes. Stops when a line break is encountered (including in the return value), EOF, or after the length-1 byte has been read (see what happens first). If length is not specified, the default is 1 K, or 1024 bytes.

Fread
(PHP 3, PHP 4)
Fread-Read files (safe for binary files)
Description
string fread (int handle, int length)
Fread () reads up to length bytes from the file pointer handle. The function stops reading the file when a package is available, either by reading the length byte number, or by reaching EOF, or (for a network stream), depending on which situation is first encountered.  

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.