The purpose is to find the number of times a particular character/word occurs in a multi-line text document. This code works:
function charnum=char_counter(fname,character)charnum=0;fid=fopen(fname,"rt");%opens file
if fid<0 || ~ischar(character) %check if file not found or character is not a char
charnum=-1; returnendoneline=fgets(fid);while ischar(oneline) for x=1:length(oneline) %compaa=re whether 'character' and words from line are same
if strcmp(oneline(x),character)==true charnum=charnum+1; end end oneline=fgets(fid);end
But when I am using strfind, it returns an empty array for each line? strfind works for single line sentences. why does it fail here?
Best Answer