Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function return of type FILE

Status
Not open for further replies.

csteinhilber

Programmer
Aug 2, 2002
1,291
US
It's late, I'm getting punchy, and I know I'm just missing something stupid... but I figured a few more sets of eyes on this would do wonders.

I'm trying to create a helper/wrapper function around a file open, such that I can pass in a mode, and the function will return the pointer to the file for subsequent reads/writes.

But every attempt so far has resulted in an "invalid conversion" error of some type or other on compile.

Code:
   void SFileMgr:ReadSave()
   {
      FILE *file=NULL;
      file = (FILE *) &GetGameSaveFile('rb');
      nb=fread(&content,sizeof(content),1,file);
   }
        

   FILE SFileMgr::GetSaveFile(const char mode)
   {
        switch(SUserMgr->GetSlotNum())
        {
           case 1:
           {
              return fopen("file1.sav", mode);
           }
           case 2:
           {
              return fopen("file2.sav", mode);
           }
           case 3:
           {
              return fopen("file3.sav", mode);
           }
           default:
           {
              return fopen("file0.sav", mode);
           }

        }

This version specifically errors @ file = (FILE *) &GetGameSaveFile('rb'); with "invalid conversion from 'int' to 'const char*'".
I know I have a pointer wrong somewhere, but I just don't see it.

Anybody have any insight?
Thanks in advance,
-Carl
 
fopen returns FILE*.
Code:
file = GetGameSaveFile("rb");
...

FILE* SFileMgr::GetSaveFile(const char mode
...
   default:
      return NULL;
 
Thanks, xwb. I could swear I had that in some iteration or other that night.

But still no joy.

file = GetSaveFile("rb");

gives me a "invalid conversion" error.

Have I mentioned I hate pointers ;-)



-Carl
 
I see you hate pointers (and vice versa;).
The string literal "rb" has const char* type, not const char as you wrote in GetGameSaveFile header.
May be better try a language w/o pointers?
 
Probably you have a keyword without asterisk key?
That's why you have troubles with pointers in C++...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top