We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
In order to take a line as input, you can use scanf("%[^\n]%*c", s); where is defined as char s[MAX_LEN] where MAX_LEN is the maximum size of s. Here, [] is the scanset character. ^\n stands for taking input until a newline isn't encountered. Then, with this %*c, it reads the newline character and here, the used * indicates that this newline character is discarded.
Note: The statement: scanf("%[^\n]%*c", s); will not work because the last statement will read a newline character,
Can someone please explain these 2 lines to me? Don't they seem contradictory?
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Playing With Characters
You are viewing a single comment's thread. Return to all comments →
Can someone please explain these 2 lines to me? Don't they seem contradictory?