Playing With Characters

  • + 0 comments

    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?