Error Reading a file

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error Reading a file

Thomas D. Dean-2
I have a problem with octave reading an ascii file, based on its
contents.  There are no strange characters in the file.  Am I doing
something wrong?

octave:1553> type xx
## Copyright (C) 2016 Thomas D. Dean
##
## This is free software: you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation, either version 3 of the License, or (at your
## option) any later version.
##
## This code is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file.  If not, see <http://www.gnu.org/licenses/>.
##

## -*- texinfo -*-
## @deftypefn{Function File} {@var row_idx}  get_row_index (@var{name})
## Function to provide the row index into the planet data array.
## get_key ( description ) will provide a cross reference from description
## to name.

octave:1554> function []=aa()
 > fp = fopen("xx","r");
 > while ( (str = fgetl(fp)) != -1)
 > disp(str);
 > endwhile;
 > fclose(fp);
 > endfunction;

octave:1555> aa
## Copyright (C) 2016 Thomas D. Dean
##
## This is free software: you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free
## Software Foundation, either version 3 of the License, or (at your
## option) any later version.
##
## This code is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this file.  If not, see <http://www.gnu.org/licenses/>.
##

octave:1556> system("hd xx")
...

shows no strange characters in the file.

Tom Dean

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Error Reading a file

Carlo de Falco-2

On 28 Jun 2016, at 20:43, Thomas D. Dean <[hidden email]> wrote:

> I have a problem with octave reading an ascii file, based on its contents.  There are no strange characters in the file.  Am I doing something wrong?
>
> octave:1553> type xx
> ## Copyright (C) 2016 Thomas D. Dean
> ##
> ## This is free software: you can redistribute it and/or modify it under
> ## the terms of the GNU General Public License as published by the Free
> ## Software Foundation, either version 3 of the License, or (at your
> ## option) any later version.
> ##
> ## This code is distributed in the hope that it will be useful,
> ## but WITHOUT ANY WARRANTY; without even the implied warranty of
> ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> ## GNU General Public License for more details.
> ##
> ## You should have received a copy of the GNU General Public License
> ## along with this file.  If not, see <http://www.gnu.org/licenses/>.
> ##
>

Reading stops here because the last line in the above is empty.
the condition

(str = []) != -1

evaluates to the empty matrix and while treats the empty matrix as 'false'

HTH,
c.









_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave