help-octave
[Top][All Lists]
Advanced

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

problem with fscanf in a loop


From: simone marras
Subject: problem with fscanf in a loop
Date: Thu, 20 Aug 2009 21:29:36 +0200

Hi everyone,

I am using fscanf to read a file made like this:

hello0
2.0 3.0
1.3 4.0
hello1
3.0 5.0
2.0 6.0
5.1 8.2
hello2
1.0 2.0
2.0 4.0

and, once I open the file correctly, I try to read it line by line and
store into an array of size [nvalues]x[2]
the floats of the file but not the strings hello0, hello1, etc.

I do it within a loop as follows

% Open file
file_name_id = fopen(file_name, "r");
if( file_name_id == -1)
     printf("!!! Error, could not open file '%s'\n", file_name);
     matrix=[];
     return;
end

% Start now reading:

i = 0;
x_curvei = 0.0;
y_curvei = 0.0;
line_cntr = 0;

        while( !feof(file_name_id))
                
                line_cntr = line_cntr + 1;
                
                string = fgets(file_name_id);
                if( strncmp(string,"# curve",7) == 0 )
                        i = i + 1
                        [x_curvei(i) y_curvei(i)] = fscanf(file_name_id, "%f 
%f\n", "C");
                end
         end

but once I run it, it enters the WHILE loop without stopping. Wha is
it that I am doing wrong in using
fscanf in the "C-type" style?

thank you in advance,
Best
cfd


reply via email to

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