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 is accepted to a newline or EOF, and stores the result of the read in the character array pointed to by the buffer pointer. The newline character is not read as the contents of the string, and the read line break is converted to the ' \ s ' null and t
Function
Sscanf ()-read data that matches the specified format from a string.
Definition
Int sscanf (string STR, string FMT, mixed var1, mixed var2 ...);
Note:
Similar to scanf, sscanf is used for input, but the latter uses the screen (stdin) as the input source, and the former uses a fixed string as the input source.The format can be one or more {% [*] [width]
The following is a detailed analysis of the usage and differences of printf (), sprintf (), scanf (), and sscanf () in C language. For more information, see
PrintfSyntax:# Include Int printf (const char * format ,...);The printf () function prints the output to STDOUT (standard output) and other parameters according to the format given by format. The return value is the number of output characters.SprintfSyntax:# Include Int sprintf (char * buffer, co
The basic knowledge of recent learning algorithms and input and output, first of all I wrote a code reference and learned a lot of resourcesThe references are given later, and they are written in more detail, and the support of regular expressions is indeed a big highlight.#include #includestring>#includeusing namespacestd;//characters and other types of conversion function LearningintMain () {//Print to a stringcout "tips for printing to a string \ n"; Chars[ -]; sprintf (s),"%d",123);//Convert
as follows:fprintf (file pointer, format control string, output Item table);For example, if the file pointer fp points to an open text file, and x and y are integer variables, the following statement outputs the integers in the x and y two integer variables in%d format to the file referred to in the FP.fprintf (FP, "%d%d", x, y);Note: For later reading, two numbers should be separated by a space. It is also best not to output additional strings for later readability.fprintf (stdout, "%d%d", x,
, the carriage return and other inputs left in the input stream can be ignored to keep the next Input"Clean". (This is acceptable on any platform)//...Char sbuf [1024];//...Fgets (s Buf, 1024, stdin );//...
InWindowsOfVCYou can do the following:
For (INT I = 0; I
{
Char CH = getchar ();
Fflush (stdin );//Every time there is a waiting status
}
Fgets () is used to read characters from the file referred to
Gets () stops reading strings from the stdin stream until it receives a linefeed or EOF, and stores the read results in the character array pointed to by the buffer pointer. The linefeed is not used as the content of the read string. The read linefeed is converted to a null value and ends the string.
Note: The gets function can be read infinitely without determining the upper limit. Therefore, the programmer should ensure that the buffer space is large enough to avoid overflow during read opera
First look at the function prototype: char* fgets (char *s, int n, FILE *stream); Char* gets (char *s); The fgets function is generally used to read the n-1 characters in the file into S, in fact, this function also has a good use is to read the string from the standard input stream, and do not worry about the number of characters entered beyond the size of the character array caused the overflow problem. H
Http://hi.baidu.com/yinjianren/blog/item/28dce5ca75e30585c9176896.html
Collection operations are supported:% [A-Z] indicates matching any character in A to Z, greedy (as many as possible)% [AB '] matches a, B, and', greedy% [^ A] matches any character other than a, greedyAre you familiar with it? Yes, it's similar to a regular expression, and it still supports filtering, that is, % * [A-Z].
Here is an example:
# Include
What is the result?
By the way, the difference between
Definition, usage and analysis of SSCANFThe sscanf () function resolves input from a string based on the specified format.
If you pass only two arguments to the function, the data is returned as an array. Otherwise, if additional parameters are passed, the parsed data is stored in these parameters. If the number of characters is greater than the number of variables that contain them, an error occurs. However, if the qualifier is less than the variabl
SSCANF ()-Reads data from a string that matches the specified format.Function Prototypes:
Int sscanf (String str, String fmt, mixed var1, mixed var2 ...);
int scanf (const char *format [, argument] ...);
DescriptionSSCANF is similar to scanf and is used for input, except that the latter takes the screen (stdin) as the input source, with a fixed string as the input source.The format can be one
1. An example of testing using scanf:#include "stdio.h"#include "string.h"int main (){Char name[10];scanf ("%s", name);puts (name);return 0;}Compile and invoke the following:Can see the second time, due to the input string length, resulting in abort2, the same example of a fgets:#include "stdio.h"#include "string.h"int main (){Char name[10];Fgets (name, ten, stdin);puts (name);return 0;}Compile and invoke t
one, the function of the approximate difference:
①fgets: Read a row of data from the file into the buffer (Fgets encountered a carriage return will end, no space and carriage return to do any conversion to the buffer, after the end of the buffer to write more than one, so it is read a row of data)
②FSCANF: Read a piece of data from a file into the buffer (fscanf encounters a space or carriage return to th
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 successfully opens fopen () or fsockopen () (and has not closed fclose ()).LengthThe end length of the read period is-1 byte.
Label: style blog color Io OS ar SP file Div
1 function input
The following two functions provide the function of inputting a row at a time.
# Include
Both functions specify the buffer address, and the row to be read is sent to it. Gets reads from the standard input, while fgets reads from the specified stream.
2 function output
Provides the ability to output a row at a time.
# Include
Example:
# Include # Define N 9Char Buf [N];Int main (){Int I
SscanfIs a runtime function, the prototype is very simple:IntSscanf (ConstChar* Buffer,ConstChar* Format[,Argument]...);Its powerful functions are reflected in the support for format and type conversion. The format can be one or more
{% [*]
[Width]
[{H
|
L
|
I64
|
L}] Type
|
'
'
|
'\ T'
|
'\ N'
|
Non-% symbol },
Note: {A | B | c} indicates A, B, and C. Select [d], which indicates D or D.
Width: width, which can be ignored. Its usage is as follows:
Const
Char
Sourcestr []
=
"Hello,
Directory
Character and number conversion: sprintf and sscanf
Brief Introduction
Instance
Running result
Conversion of characters and numbers: sprintf and sscanf
Both sprintf and sscanf are functions in the stdio. h header file. Please feel free to use them ~
Sprintf can convert any number, including the decimal point (.) and minus sign (-), t
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.