I
imailz
Hi all,
since I'm forced to switch from Fortran to C I wonder if there is
posibility in C:
1) to use implicit loops
2) to parse several variables which number is determined at runtime.
Following example:
The output contains n columns which have to be read in. The number of
the columns is determined only at runtime. The length of the columns
is m. So an implicit loop can be used to read in the elements. In
Fortran this problem can be solved by three lines:
READ(*,*),n
x='(nF10.5)'
READ(*,x),((var(i,j),i=1,n),j=1,m)
To do the same in C I have a temporary solution:
for (i=0;i<m;i++)
{
fgets(buffer,300,file);
sscanf(buffer,"%f %f %f\n",&var1,&var2,&var3);
}
Which is also ok, but the number of variables is already defined at
compilation. Since this procedure has to be repeated several times, I
would like to avoid any "if"-constructs. Are there similiar tools in
C like the two aforementioned in Fortran?
Thanks in advance!
since I'm forced to switch from Fortran to C I wonder if there is
posibility in C:
1) to use implicit loops
2) to parse several variables which number is determined at runtime.
Following example:
The output contains n columns which have to be read in. The number of
the columns is determined only at runtime. The length of the columns
is m. So an implicit loop can be used to read in the elements. In
Fortran this problem can be solved by three lines:
READ(*,*),n
x='(nF10.5)'
READ(*,x),((var(i,j),i=1,n),j=1,m)
To do the same in C I have a temporary solution:
for (i=0;i<m;i++)
{
fgets(buffer,300,file);
sscanf(buffer,"%f %f %f\n",&var1,&var2,&var3);
}
Which is also ok, but the number of variables is already defined at
compilation. Since this procedure has to be repeated several times, I
would like to avoid any "if"-constructs. Are there similiar tools in
C like the two aforementioned in Fortran?
Thanks in advance!