Originally Posted by
abood1190
ok .. i did what you said but its still the same
Code:
fscanf(file1,"%d %c",&Num_Of_Bays,&Harbour_Name); for (i=0;i<Harbour_Name;i++){
i!=EOF;
fscanf(file1,"%d %d %d %1f",&Docking_ID,&Max_size,&Time_Taken,&Chargs);
}
First of all ... learn how to organize your code for readability.
Code:
fscanf(file1,"%d %c",&Num_Of_Bays,&Harbour_Name);
for (i=0;i<Harbour_Name;i++)
{
i!=EOF;
fscanf(file1,"%d %d %d %1f",&Docking_ID,&Max_size,&Time_Taken,&Chargs);
}
Now look at your file format...
On that first line you have an integer number and a string... not an integer number and a character. Since you are reading only the first character of the string, your file pointer is misplaced and it will read the rest of the file as garbage.
Also your loop want to exit on the the wrong variable... try using Num_Of_Bays instead of the first letter in the name.
the i!=EOF; line does exactly nothing.
In your fscanf() format string you use 1f (one eff), which is an invalid formatting string... you want Chargs to be a float value and you should use simply %f to read it.
Also from your original code...
You have two #includes on the same line... the compiler's not going to like that.
You are also using the C++ keywords "using" and "namespace" both of which should produce syntax errors in C.