How to initialize a defined variable with a type of _IO_FILE?

I want to use _IO_FILE and initialize it by a file path.

I defined f:
_IO_FILE f;


but I cannot init it by a file name and then pass it to Func1 which is defined as follows:
int Class1 :: Func1 (List& _list, FILE& _file)

I tried by using fopen(filename,"r"); but it does not work.
Last edited on
Last edited on
I cannot change the func1, so I need the type of __IO_FILE aka FILE.
I see you're using C style file handling. Well watch this -

https://www.youtube.com/playlist?list=PL6gx4Cwl9DGAKIXv8Yr6nhGJ9Vlcjyymq

Video 50-53.
1
2
3
4
Class1 c;
	FILE * f;
	f=fopen("filename","r");
	c.func1(l, f);


no known conversion for argument 2 from ‘FILE* {aka _IO_FILE*}’ to ‘FILE& {aka _IO_FILE&}’


int Class1 :: Func1 (List& _list, FILE& _file)
int Class1 :: Func1 (List& _list, FILE& _file)

"_file" is a pointer. You cant send it in via reference. Change it to

int Class1 :: Func1 (List& _list, FILE* _file)
I should not change the FILE& to FILE*.
Last edited on
What are you talking about?

1
2
3
4
class1 c;
	FILE * f;
	f=fopen("filename","r");
	c.func1(l, f);


'f' is a pointer, and should be sent in as such.

Read this page - http://www.tutorialspoint.com/cprogramming/c_file_io.htm
Is there any solution that I can define different way f and then pass it to the func1 (by FILE&)?
Last edited on
I mean... It looks like you're using classes, which means you're coding in c++ but still you're using C-style file-handling which makes no sense to me. I know that in c++ style file handling you can send in by reference, but in C Im honestly not sure, hopefully someone with that knowledge can come and answer your question.

Why are you using c-style file handling?
I need to add new codes to provided function. Is anyone has a suggestion?
Last edited on
Topic archived. No new replies allowed.