Clear Filters
Clear Filters

fscanf problem

3 views (last 30 days)
oblivious
oblivious on 19 May 2012
hello, this is a very simple problem. but i cant figure it out. i have a text file. it contains a line
'read this line'.
when i write a=fscanf(fid,'%c') it shows
a= read this line.
but when i write
a=fscanf(fid,'%c '),
with a space after %c, it shows
a=readthisline.
what happens when i put that space?
-obli

Answers (1)

Walter Roberson
Walter Roberson on 19 May 2012
Inside input formats, any character which is given literally is a character that is to be matched against in input, and discarded when found. For example if you had a format of '%c<%c>' then the '<' and '>' would have to appear in the input and would be "eaten" and thrown away. The space character is not special in this regard (but it can often look like it because spaces and tabs and newlines at the beginning of a field are ignored for all formats other than %c and %[ )

Categories

Find more on Data Import and Export in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!