Friday, July 31, 2009

C programming help with scanf?

by referring to the code below:





void digestline(void) {


scanf("%*[^\n]"); /* Skip to the End of the Line */


scanf("%*1[\n]"); /* Skip One Newline */


}





can anyone explain what the [\n] parts are? I couldn't find any documentation online referring to such a format.





(I found this code on http://vergil.chemistry.gatech.edu/resou... )

C programming help with scanf?
y not dear





% hope u know it so i m not explaining it





* to read all chars from the input (keyboard iostream / io buffer)








[] what is contained in it is an regular expression





^ tells not





\n a new line char





so the first scanf will skips all characters until the newline char is found...





where as the second scanf function allows u to only read new line char only and only once ie. while storing to any char array u also stores there a new line char but in case of first u didnt i.e. u discarded the storage if a new line char occurs....





but i let u know to which variable the values are going is missing.................





anyway rank my answer which encourage me to answer more


http://www.geocities.com/ankur899/
Reply:The asterisk means the read value will not be stored in any variable, and the [^\n] just means read an entire line. %*[^\n] will accept any character except \n.





This is cheating by using regular expressions. Its not really standard C.

memory cards

No comments:

Post a Comment