I'm working on a function in MATLAB that reads input from a file. So far (after reading a bit here about scanf
vulnerabilities) I decided to use fgets
to get each line, and then textscan
to extract the words, which will always be of the format 'chars' including the apostrophes. So, I'm using:
fid = fopen('file.txt');
tline = fgets(fid);
textscan(tline, '''%s''');
However, I want to allow people to have comments, using the % character. How do I cut off textscan
so that
'word' 'anotherword' % 'comment'
doesn't return comment?