I can't understand the errors that crop up due to the following code.I am trying to open a file using fopen(), but the errors make no sense to me.So please explain the whole thing.
10 - FILE * THE_FILE_YOU_READ;
11 - THE_FILE_YOU_READ = fopen("num.txt","r");
These two line alone produces several warnings and errors,as follows:
11 - warning: data definition has no type or storage class [enabled by default]
11 - error: conflicting types for 'THE_FILE_YOU_READ'
10 - note: previous declaration of 'THE_FILE_YOU_READ' was here
11 - warning: initialization makes integer from pointer without a cast [enabled by default]
11 - error: initializer element is not constant
I'm using Code::Blocks if it's relevant at all. I have not declared this variable `THE_FILE_YOU_READ anywhere else in the program. Any ideas, or is this simply a stupid oversight on my part?
You've written this code outside of any function, at the file scope. That's invalid. Statements can only occur in functions. Outside of a function, the compiler is trying to interpret the second line as a declaration/definition, with an implicit type of int.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With