I am creating a function that counts the given character present in the text file. Problem I am facing is if the text file is not found the function should return value -1 and also if the given character is not a valid one it should return -1.
function [charnum]=char_counter(fname,character)fid=fopen(fname,'rt')if fid<0 || ischar(character)==0 charnum=-1;elsestr=fileread(fname);if strncmpi(character,str,inf)==0 charnum=-1;endcharnum=count(str,character);end
Best Answer