[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: sscanf
From: |
mavram |
Subject: |
Re: sscanf |
Date: |
Mon, 4 Apr 2005 20:42:15 +0300 |
User-agent: |
Mutt/1.5.5.1+cvs20040105i |
On Mon, Apr 04, 2005 at 06:39:52AM -0500, bertrand roessli wrote:
> Hello,
>
> I cannot find a way to read from a file a line
> that contains both numbers and characters (the length of the
> line might vary).
>
> e.g.:
>
> if the line reads
>
> ctave:1> a='1 2 dsf sdaf'
> a = 1 2 dsf sdaf
>
> then
> octave:2> [c,v]=sscanf(a,'%f%10c',"C")
> c = 1
> v = 2 dsf sda
>
> works but
> octave:3> [c,v]=sscanf(a,'%f%100c',"C")
> c = 1
> v = [](0x0)
>
> and
> [c,v]=sscanf(a,'%f%100s',"C")
> c = 1
> v = 2
>
> Thank for help,
>
> B. Roessli
>
> --
> Dr. Bertrand Roessli
> Laboratory for Neutron Scattering
> ETHZ and Paul Scherrer Institut
> CH-5232 Villigen, PSI
>
>
>
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
>
> Octave's home on the web: http://www.octave.org
> How to fund new projects: http://www.octave.org/funding.html
> Subscription information: http://www.octave.org/archive.html
> -------------------------------------------------------------
>
Hi,
If I understood correctly your letter the answer is the function
fgetl:
645~> fid=fopen("file","t")
error: invalid mode specified
error: fopen: internal error
error: evaluating assignment expression near line 2, column 4
646~> fid=fopen("file","rt")
fid =
{
id = 3
name = file
mode = r
arch = ieee_little_endian
status = open
}
646~> fgetl(fid)
ans = 1 2 dsf sdaf
648~> fgetl(fid)
ans = a,'%f%10c',"C"
648~> fgetl(fid)
ans = ,'%f%100c',"C"
649~> fgetl(fid)
ans = a,'%f%100s',"C"
650~> fgetl(fid)
ans = -1
651~> fclose(fid)
ans = 0
The file "file" is attached.
Cheers, Avraham
file
Description: Text document
- sscanf, bertrand roessli, 2005/04/04
- Re: sscanf,
mavram <=
- Re: sscanf, Miquel Cabanas, 2005/04/05
- Message not available