if ( sscanf( line, "%[^ ] %[^ ] %[^ ]", method, url, protocol ) != 3 )...
That format above is very strange,what's it doing?
Definition of oops —used typically to express mild apology, surprise, or dismay.
Any programming language that makes use of objects, classes, added to its abstraction, encapsulation, and polymorphism are said to be Object-Oriented Programming Language or OOPs.
Object-Oriented Programming in C Although the fundamental OOP concepts have been traditionally associated with object-oriented languages, such as Smalltalk, C++, or Java, you can implement them in almost any programming language including portable, standard-compliant C (ISO-C90 Standard).
OOP concepts in Java help the programmer to control and access the data and improves code readability and reusability using the core concept of OOPs i.e., Abstraction, Encapsulation, Inheritance, and Polymorphism.
That line is attempting to read 3 strings that do not contain a space separated by spaces into method, url, protocol and if it fails to read 3 it will then enter the if block.
the []
is the scanset. If you tell %[abcd]
then an input string only with a or b or c or d will be considered. The string would terminate at the first occurance of some other character which is not any of the characters in the braces.
The ^
inside the []
is used to denote the compliment of the set inside the braces. Like with the format string %[^abcd]
will only accept all characters except , a or b or c or d.
so in %[^ ]
, the blankspace followed by the ^
tells that, the format string will accept any character combination in the string which does not have a blankspace.
The format string "%[^ ] %[^ ] %[^ ]"
will match a string which has three components separated by blankspaces. Each of the component will contain a sequence of characters which have no space inside them.
The function returns the number of input items successfully matched and assigned, which can be fewer than provided for, or even zero in the event of an early matching failure.
So the above function will return 3
only if and only if all the three components are read, that is, the input line has three partitions and for each partition the three arrays method
, url
and protocol
was populated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With