Difference between `”%[^\n]”` and `”%[^\n]\n”` and `”%[^\n]%*c”` in C how do they work?

309    Asked by dhanan_7781 in Java , Asked on Nov 3, 2023

Dive into the difference between`”%[^n]”` and `”%[^n]n”` and `”%[^n]%*c”`. What is its significance in terms of input and output? 

Answered by Dhananjay Singh

`”%[^
]”` This scans a unit until a newline character is countered. Therefore, this sign is here to read characters till the time when finally a new character is hit by input.

`”%[^
]
”` This sign or read characters shows that until a new line is found and consumes the character of the new line. It is just like same as “%[
]”. The only difference between both is that it consumes the newline character after the input is read.

`”%[^
]%*c” This reads characters until a new line is encountered. However, it does not consume the character of the new line. The “%*c” at the end directive to read and discard the next character.


Your Answer

Interviews

Parent Categories