Supossedly, it must be the same in the output file, because I'm just printing what it scanned, to check if it is doing it correctly, but the output data that I get is like this...
I'm using Visual C++ 2008, when compiling no errors appear, it runs fine, so when I was trying to verify if this part of my program worked correctly I realized that it is not scanning right. So I suppose I'm not using correctly the fscanf function or something, I've tried specifing the integer with %i or with %d or even %hi, but I got the same output.
The code I'm using is...
#include <iostream>
FILE *in1, *out1;
int TotEnc = 120;
int i = 0;
int ImageEACC;
int ImageERESP;
float ImageERT;
int RespCor;
int StimNum;
int StimTypeE;
Can you help me understand where does the data printed in the output come from, or what am I missing, or doing wrong. Thank you very much in advance...
When doing I/O operations, you need to check for errors every step of the way. So, after every fopen(), fscanf(), fprintf(), fseek(), etc. check the return value for error conditions (and ferror() if needed) and report any errors encountered.
Thanks for your advice, that is what I intended by checking if the code was scanning the data correctly when trying to print it, although as you suggest I must check every step deeper. I've been trying to check the return value of each function I use in the code, as far as I've got it does open the file correctly. But when I tried to check the return value of the fscanf function this error appeared...
Compiler Error C2660
'fscanf' : does not take 0 arguments
I've been looking how to fix it, but as far as I have found it is caused because the function is called with an incorrect number of parameters.
I'm not sure if I'm checking the return value correctly, I added this while after each fscanf:
Thank you, and I apologize if I result annoying, I suppose my questions are too obvious, or something, since only you replied me. I've been searching in the forums before I posted, but I really didn't find an answer that help me understand what am I doing wrong.
The error is telling you that this line of your code doesn't work:
int ImageEACC = fscanf( /* ... */ );
I believe the problem is that %i is not a format specifier for fscanf, you want %d for integers.
btw- this isn't the actual code line is it? I mean the actual code line looks like the fscanf right before the loop right?
What you should do is make a normal call to fscanf, but use ImageEACC as the return value. Then you can check ImageEACC for EOF or for the number of items successfully scanned.
So
int ImageEACC;
ImageEACC = fscanf(in1,"%d", &ImageEACC);
Hi, thank you both (jpeg and kevinchkin) for your replies...
Yes I know the error message refers to the line that includes
int ImageEACC = fscanf( /* ... */ );
That is why I'm not sure if I was checking the return value correctly (since PanGalactic suggested me to check the return value of each function I use in the code), in the actual code I didn't include the while I mentioned in my second post, I tried to use that while to check the return value of the fscanf.
As I mentioned in my first post, where the actual code is, I've also used %d to specify the integer, but the result is the same as with %i.