Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oops what does this mean in c?

Tags:

c

if ( sscanf( line, "%[^ ] %[^ ] %[^ ]", method, url, protocol ) != 3 )...

That format above is very strange,what's it doing?

like image 466
compile-fan Avatar asked May 20 '11 14:05

compile-fan


People also ask

What OOPs means?

Definition of oops —used typically to express mild apology, surprise, or dismay.

Why C is called OOP?

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.

Can OOPs be applied in C?

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).

What is the use of OOPs?

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.


2 Answers

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.

like image 109
Joe Avatar answered Oct 19 '22 12:10

Joe


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.

like image 27
phoxis Avatar answered Oct 19 '22 13:10

phoxis