[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to read txt file and output to display
From: |
Mike Miller |
Subject: |
Re: How to read txt file and output to display |
Date: |
Thu, 14 Mar 2019 14:18:11 -0700 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Thu, Mar 14, 2019 at 15:30:38 -0500, sb wrote:
> I have a txt file which includes a help text for a program that I am trying
> to write.
> I want to display its contents to the display (i.e. read from txt file and
> flush its content to the display) when selected from a menu.
> I couldn't find the exact command to do this (if any)?
> Most of the commands refer to reading data with delimiters. I want to read
> from a simple txt file which includes text (any length and any number of
> lines).
> Is this possible?
Of course. The simplest solution is probably the 'type' function:
filename = "/path/to/README.txt";
type ("-q", filename)
Another very easy way is the 'fileread' function:
filename = "/path/to/README.txt";
disp (fileread (filename));
Or if you like to read the file line-by-line:
filename = "/path/to/README.txt";
fid = fopen (filename, "r");
while (! feof (fid))
s = fgets (fid);
fputs (stdout, s);
endwhile
fclose (fid);
--
mike
signature.asc
Description: PGP signature