I need help interpreting fscanf(fptr,"%*[^\n]"); this part of the code. I dont undertand how the output could be obtained. Thanks.
I need help interpreting fscanf(fptr,"%*[^\n]"); this part of the code. I dont undertand how the output could be obtained. Thanks.
"%*[^\n]" instructs fscanf to read and discard a sequence of characters of any length, until a newline is encountered or there is nothing left to read. If a newline is read, fscanf returns and the newline is pushed back onto the stream, to be considered by a following read on the same stream.
The asterisk *, or assignment suppression character, instructs fscanf to simply read any data matching the current specification from the stream and discard it, without storing it in any object.
The [^\n] specification describes a scanset which matches a sequence of characters that contains one or more characters that are not the newline character. The brackets [] delimit the scanset, the presence of a circumflex ^ as the first character indicates inversionĀ—to match all characters which are not in the set rather than characters which are, and the newline character \n is the entire list of characters contained within the set.
Take the time to read the documentation for fscanf if you get the chance, you can do a search on the Web, or better yet have a read of Appendix B1.3 of “The C Programming Language (Second Edition)” by Kernighan and Ritchie.
Does that help?
Last edited by stillmotion; 05-07-2018 at 10:45 PM.