[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem using fscanf

From: Bård Skaflestad
Subject: Re: Problem using fscanf
Date: Fri, 15 Apr 2011 09:53:04 +0200

On Fri, 2011-04-15 at 07:34 +0200, Utherr13 wrote:
> It only shows me the first line. I want all lines from the file.

What is "it"?  Your original code?

Did you try my suggestion?  Here's a more complete demonstration.  Maybe
you can pinpoint the spot where this approach does not produce the
results you expected:

   # Create test data file:
   x = floor(100 * rand([100, 2]));  # create some data
   f = fopen("data.txt", "w");       # error checking omitted
   fprintf(f, "%d %d\n", x .');      # output data to file

   # Read data back in:
   f = fopen("data.txt", "r");       # error checking omitted
   t = fscanf(f, "%d", [2, 100]) .'; # [2,100]+transpose essential
   # Compare to original
   all(all(t == x))

By the way, this problem might be easier to attack using the "load"

Bård Skaflestad <address@hidden>
SINTEF ICT, Applied Mathematics

reply via email to

[Prev in Thread] Current Thread [Next in Thread]