annotate readFile.m @ 3:ace890ed0ed9 default tip

Use lookup to look for all words at once
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sat, 10 Dec 2011 15:56:02 -0500
parents f602dc601e9e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
1 function file_contents = readFile(filename)
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
2 %READFILE reads a file and returns its entire contents
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
3 % file_contents = READFILE(filename) reads a file and returns its entire
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
4 % contents in file_contents
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
5 %
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
6
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
7 % Load File
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
8 fid = fopen(filename);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
9 if fid
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
10 file_contents = fscanf(fid, '%c', inf);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
11 fclose(fid);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
12 else
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
13 file_contents = '';
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
14 fprintf('Unable to open %s\n', filename);
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
15 end
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
16
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
17 end
f602dc601e9e Initial commit
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
diff changeset
18