Specifier | Field type | Converted using | Arg is pointer to |
d | Integer (optionally signed) | Strtol with base 10 | Int |
hd | '' | '' | Short int |
ld | '' | '' | Long int |
I | '' | Strtol with base = 0 Reads 045 as octal Ox92 as hexadecimal | |
hi | Short | ||
li | '' | '' | Long |
O | Integer | Strtoul base 8 | Unsigned int |
ho | '' | '' | Unsigned short |
Lo | '' | '' | Unsigned long |
U | '' | Base 10 | '' |
Hu | '' | '' | '' |
Lu | '' | '' | '' |
X | Integer | Strtoul base 16 Does not accept AB | Unsigned int |
Hx | '' | '' | '' |
Lx | '' | '' | '' |
E | Floating point input field | Strtol | Float |
le | '' | '' | Double |
Le | '' | '' | Long double |
fscanf
-----------------------------------------
#include <stdio.h>
int fscanf(FILE*stream, const char * format, ...)
scanf is like fscanf(stdin,...)
sscanf(const char* src, ...format...
return value = # of text fields converted to values that are stored
scanf("%d %f", &n,&x)
return EOF if the function stops scanning
because the attempt to get next character it sets end of file or error indicator
for stream ferror(fp), feof(fp)
--------------------------------------------
format string
---------------------------------------------
can have white space
matches any amount of whitespace in the input
"%d<>%f
<> represents a space
literal text
scan conversion specifier
-like those from printf ( sort of )
-------------------------------------------------
conversion specifier
---------------------------------------------------
-start w/ % sign
-*assignment supression
looks like scanf(%d %*d %d &m)
-w field width
-conversion specifier
-give type of argument to expect
-always a pointer to something
-how to determind conversion field
-how to convert value to store
(a) scan set
[ ]
keep reading any of these characters (above)
{^ }
Don't read these characters (above)
b) otherwise (and usually)
d
i
o hl
u
x
X
d and i are different in scan f
eE
fF lL
gG
c
s
n
p
-------------------------------
%wc w chars no '\0' appended store arg char*
defaults to 1 for %c
%ws w chars charx then append '\0'
default %s all of next token
scanf("%10c", buf) reads first 10 chars even if it is whitespace
scanf("%10s", buf) skips all the whitespace reads first 10 chars
char *p;
strtol(" 347atx ", &p, 6);
//skips whitespace and reads legal digits in 'this' base (this being 6)
//returns 22 (3 sixes + 4) and pointer p points to the 7
if value outside the range it will return LONG_MAX/ LONG_MIN + set errno to ERANGE
0 <-- system call
-1
x
---------------------------
file* <--Fopen
NULL
x
------------------------------
perror("usermessage"); prints out "usermessage: system error messsage" error message corresponding to error number
strerror(errno) returns appropriate error string
No comments:
Post a Comment