The string str will be matched against the format string fmt. fmt can contain strings separated by %d,%s,%c and %f. Every % corresponds to one lvalue. An lvalue is the name of a variable, a name of a local variable, an index in an array, mapping or object. It is because of these lvalues that sscanf can not be implemented as a normal function.int sscanf(string str, string fmt, lvalue ...)
Whenever a percent is found in the format string, a match is according to the following table:
%b | reads a binary integer |
%d | reads a decimal integer |
%o | reads an octal integer |
%x | reads a hexadecimal integer |
%D | reads an integer that is either octal (leading zero), hexadecimal (leading 0x) or decimal. |
%f | reads a float |
%c | matches one char and returns it as an integer |
%2c | matches two chars and returns them as an integer (short) |
%4F | matches four chars and returns them as a float (IEEE single precision) |
%8F | matches eigth chars and returns them as a float (IEEE double precision) |
%s | reads a string. If followed by %d, %s will read any non-numerical characters. If followed by a %[], %s will read any characters not present in the set. If followed by normal text, %s will match all characters up to but not including the first occurrence of that text. |
%5s | gives a string of 5 characters (5 can be any number) |
%[set] | matches a string containing a given set of characters (those given inside the brackets). %[^set] means any character except those inside brackets. Example: %[0-9H] means any number or 'H'. |
%{format%} | Repeatedly matches 'format' as many times as possible and assigns an array of arrays with the results to the lvalue. |
If a * is put between the percent and the operator, the operator will only match its argument, not assign any variables.
Sscanf does not use backtracking. Sscanf simply looks at the format string up to the next % and tries to match that with the string. It then proceeds to look at the next part. If a part does not match, sscanf immediately returns how many % were matched. If this happens, the lvalues for % that were not matched will not be changed.
Let's look at a couple of examples:
// a will be assigned "oo" and 1 will be returned
sscanf("foo","f%s",a);
// a will be 4711 and b will be "bar", 2 will be returned
sscanf("4711bar","%d%s",a,b);
// a will become "test"
sscanf(" \t test","%*[ \t]%s",a)
// Remove "the " from the beginning of a string
// If 'str' does not begin with "the " it will not be changed
sscanf(str,"the %s",str);
SEE ALSO : sprintf
If an error occurs, catch will return a description of the error. The description of the error has the following format:catch { statements }
If no error occurs, catch will return zero. You may emulate your own errors using the function throw, described in chapter 16 "Builtin functions".({
"error description",
backtrace()
})
Example:
int x,y;
// This might generate "division by zero"
mixed error=catch { x/=y; };
However, gauge simply returns how many seconds the code took to execute. This can be used to find out how fast your code actually is.. :) Only CPU time used by the Pike process is measured. This means that if it takes two seconds to execute but only uses 50 % CPU, this function will return 1.0.gauge { statements }
This will return the string "void" since exit is a function that returns void. It will not execute the function exit and exit the process as you might expect.typeof( exit(1) )
If you want to know the type after evaluation, use sprintf("%t", expr).