There are several ways to read a string in C, such as scanf () with%s, but this method can only get one word, which means that a null character, such as a space, is returned. If you want to read a line of strings, for example:
I Love BIT
In this
PHP fgets () function is used to read a row from the file pointer, the function can be combined with the feof function to read the contents of the file, this article to share with you PHP use Fgets () read/Get the file content of a simple example
There are several ways to read a string in the C language, such as scanf () with%s, but this method can only get one word, that is, a null character, such as a space , is returned. If you want to read a line of strings, such as:I Love BITIn this
Gets the string function read from the standard input device. Can be read indefinitely without judging the upper limit to return to the end of the read. The function's specific functions are as follows: reads a string from the stdin stream until it
Fgets () function: for reading file strings
Header files: include
Function Description: The fgets () function is used for reading characters from the file referred to in the parameter stream to the memory space referred to by parameter s, knowing
The fgets () function reads a row from the file pointer.
Grammar
Fgets (File,length)
Parameters
Description
File
Necessary. Specifies the file to be read.
Length
Optional. Specifies the number of
#include #define MAXLINE 20int main (void){Char Line[maxline];while (Fgets (Line,maxline,stdin)!=null && line[0]! = ' \ n ')Fputs (line,stdout);return 0;}The fgets () function is the address (char * type) used to store the input. The second argument
PHP with Fgets read the string, it would have encountered a newline stop reading, but the actual will be in the back of the string to read something, I feel is the cause of Windows line, \ r \ n, this may be the reason, there is always a space,
fgets-reading a line from the file pointer
Description
String fgets (Resource $handle [, int $length])
Reads a row from the file pointer.
Parameters
The handle file pointer must be valid and must point to a file that was successfully opened by
Fgets ()--------------------------------------------Char * fgets (char * s, int size, file * stream );S is the buffer for saving the read contentSize indicates the buffer size.Stream is a file pointer.Fgets () functionRead the first line break it
Recently write PHP code to read text lines from a text file (text file is the ANSI character set)
PHP 2 built-in functions file and fgets can implement this function
file-to read an entire file into an array
fgets-reading a line from the file
Fgets ()Fgets () The function is a file operation related function temporarily using this function can receive a string from the keyboard, save to the character array of the original received string saved to the array method:
Fgets(PHP 4 and PHP 5)Fgets-get the pointer to the line slave fileDescriptionString fgets (resource $ processing [Summary $ length])Get the line from file pointer.ParametersHandleThe file pointer must be valid and must point to a file that
Fgets (buf, size, FP)It acts in the following manner:(1) returns when a newline or file end EOF is encountered.(2) Read by row.(3) The newline character '/n ' at the end of each line is also the line character.(4) for buf sizes of size, read only
1. stream and Buffer
Stream I/O is provided by standard functions in C language. These I/O can replace the Read and Write functions provided in the system. In fact, the stream I/O encapsulates the two basic file read/write system calls. To some
Reading and Writing files is more complex than opening and closing files. Here we will explain how to read and write data.
Php file processing-how to read a file (one row, the entire file)
Reading and Writing files is more complex than opening and
first of all, fscanf and fgets These two file functions of the concept of a deep understanding of the string input for the two functions have a typical difference is: fscanf read a space or carriage return will be converted to a blank space or enter/
C Language File operationsI. Reading and writing of standard documents1. Opening of the fileThe open operation of the fopen () file indicates that the user-specified file will be allocated in memory with a single file structure and a pointer to the
In the programming found gets and fgets some differences summed up;
1, fgets than get safe, use gets compile warning
For security, get is less used because it does not specify the size of the input character, restricts the size of the input buffer,
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.