llllllllllllllll
Printable View
llllllllllllllll
In ReadFile you should be reading from a file not from the keyboard. Surely those scanf's should be fscanf's. Also drop the ncircles parameter completely as that variable is global as are s and t which can also be dropped.
cccc
the variables you pass into the function are all GLOBAL. that means they can be accessed from everywhere. The only parameter that function needs is the filename. fscanf is slightly different to scanf. it requires a FILE* too. scanf reads only from the keyboard assuming stdin hasn't been redirected.
At the moment, you open a file for reading, try to get input from the keyboard, then close the file.
int fscanf ( FILE * stream, const char * format, ... );
thats the prototype for fscanf. See the first parameter is the file pointer which is why you got that error.
scanf is equivalent to fscanf( stdin, .......... ) which is why it never needs that parameter. its hardwired.
fff
For starters change it to
change the call to ReadFile in main to only pass the filename.Code:void ReadFile( const char* filename )
change the scanf's to fscanf's with the FILE* as the first parameter.
oooo
Give up programming its not for you!
Ever going to do anything in particular with that open file pointed to by the FILE* called file??Code:FILE *file;
if (( file = fopen( filename, "r" )) == NULL )
[[[[
btw you will also need to drop the asterix here
i<*ncircles
as ncircles is a global int, not an int* so dereferencing it is completely wrong.
fscanf( file, .............. )
how hard can it be. you open the file but never read from it. You have to tell the fscanf where to read from.
qqqq
Use your debugger and find out. Learning to debug your code is part of learning to program. work out on pen and paper what values you expect in variables and watch to see whats actually happening as you step through your code. When you see something unexpected, work out what went wrong and fix it.
aaa
You wrote the code, therefore you must have known what every variable, function, line of code does.
Therefore, what is stopping you from debugging your own code? You wrote it, right? So why can't you debug something you wrote? As was stated, learning to debug your programs is part of learning how to program. So asking us to do the work you're supposed to have done is almost and maybe, just as bad as one of us writing the code for you.
Regards,
Paul McKenzie