-
Problem with fscanf..
C Warning:
Argument is incompatible with the corresponding format string conversion.
fscanf(outfile, "%f", &out[i][j][k]);
What is the issue here? The syntax is correct... does this occur because out is passed into the function as a pointer already? If so how do I work around it. (Currently I get garbage out and the fscanf doesn't appear to be working when I do a dump of the out array within the subprogram)
Here's more of the function code, the file is opened in the main program.
int InitFile(FILE *outfile, float *out)
--Declarations
Loop 1{
Loop 2 {
Loop 3 {
fscanf(outfile, "%f", &out[i][j][k]);
}
fscanf(outfile, "\n");
}
fscanf(outfile, "\n,\n");
}
I'm assuming the problem is because out is already declared as a pointer prior to the fscanf command, if I do the read in the main (w/o the pointer) program it seems to work correctly... however this piece of code will be used by many programs so I was hoping to make it a function so that it would be accessed in only one place if it needed to be edited.
Any help you can provide would be greatly appreciated.
-
>Argument is incompatible with the corresponding format string conversion.
It means that you're trying to read a float but the data in the file is not a float. Double check the file to see that you're actually reading what you think you are.
-
The data is indeed a float
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
1.000 1.000 1.000 1.000
That is the contents of the test file it should be reading.
-
But how is the 'out' array declared in main?
Because
int InitFile(FILE *outfile, float *out)
is all wrong if it's a 3D array
-
Oops the actual start of the file is:
int InitFile (FILE *outfile, float *out[i][j][k])
In main its declared:
float out[i][j][k]
and the function call is
rstat = InitFile (&outfile, &out);
-
Well that's the problem then
Given the following array (where i, j, k are constants)
float out[i][j][k];
The function prototype is
int InitFile (FILE *outfile, float out[i][j][k] )
The call is
FILE *outfile = fopen( "file.txt", "r" );
rstat = InitFile ( outfile, out );
And within the function, the file is read like so
fscanf(outfile, "%f", &out[x][y][z] );
-
Won't eliminating the pointer on the out variable, mean that I can't modify it in the function and still have the results available in the main?
-
The results will be in the array declared in main
-