c sscanf prog..........

sscanf 한번 정리하고,

이번에 고민했던것은,
%s로 떼올때는 white space로 이어진 string을 다 못가져오고, white space에서 끊어서 읽어오게됨

이런 경우는 %s로 떼오는게 아니라

이렇게 떼오게 되면 tab 또는 개행문자를 만날때까지의 값들을 다 떼올 수 있음

specifierDescriptionCharacters extracted
iIntegerAny number of digits, optionally preceded by a sign (+ or -).
Decimal digits assumed by default (0-9), but a 0 prefix introduces octal digits (0-7), and 0x hexadecimal digits (0-f).
Signed argument.
d or uDecimal integerAny number of decimal digits (0-9), optionally preceded by a sign (+ or -).
d is for a signed argument, and u for an unsigned.
oOctal integerAny number of octal digits (0-7), optionally preceded by a sign (+ or -).
Unsigned argument.
xHexadecimal integerAny number of hexadecimal digits (0-9a-fA-F), optionally preceded by 0x or 0X, and all optionally preceded by a sign (+ or -).
Unsigned argument.
fegFloating point numberA series of decimal digits, optionally containing a decimal point, optionally preceeded by a sign (+ or -) and optionally followed by the e or E character and a decimal integer (or some of the other sequences supported by strtod).
Implementations complying with C99 also support hexadecimal floating-point format when preceded by 0x or 0X.
cCharacterThe next character. If a width other than 1 is specified, the function reads exactly width characters and stores them in the successive locations of the array passed as argument. No null character is appended at the end.
sString of charactersAny number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.
pPointer addressA sequence of characters representing a pointer. The particular format used depends on the system and library implementation, but it is the same as the one used to format %p in fprintf.
[characters]ScansetAny number of the characters specified between the brackets.
A dash (-) that is not the first character may produce non-portable behavior in some library implementations.
[^characters]Negated scansetAny number of characters none of them specified as characters between the brackets.
nCountNo input is consumed.
The number of characters read so far from stdin is stored in the pointed location.
%%% followed by another % matches a single %.
Except for n, at least one character shall be consumed by any specifier. Otherwise the match fails, and the scan ends there.

The format specifier can also contain sub-specifiers: asterisk (*), width and length (in that order), which are optional and follow these specifications:
*An optional starting asterisk indicates that the data is to be read from the stream but ignored (i.e. it is not stored in the location pointed by an argument).
widthSpecifies the maximum number of characters to be read in the current reading operation (optional).
lengthOne of hhhllljztL (optional).
This alters the expected type of the storage pointed by the corresponding argument (see below).

This is a chart showing the types expected for the corresponding arguments where input is stored (both with and without a length sub-specifier):
lengthd iu o xf e g ac s [] [^]pn
(none)int*unsigned int*float*char*void**int*
hhsigned char*unsigned char*signed char*
hshort int*unsigned short int*short int*
llong int*unsigned long int*double*wchar_t*long int*
lllong long int*unsigned long long int*long long int*
Llong double*
Note: Yellow rows indicate specifiers and sub-specifiers introduced by C99.
scanf - buffer overflow에 취약..및 space들어있는거 처리못하는거

정리할것 fgets


댓글 입력 영역

통계 위젯 (화이트)


통계 위젯 (블랙)


이 이글루를 링크한 사람 (블랙)