×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Function return of type FILE

Function return of type FILE

Function return of type FILE

(OP)
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

RE: Function return of type FILE

fopen returns FILE*.

CODE

file = GetGameSaveFile("rb");
...

FILE* SFileMgr::GetSaveFile(const char mode
...
   default:
      return NULL;
 

RE: Function return of type FILE

(OP)
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  winky smile
 


-Carl
 

RE: Function return of type FILE

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?
 

RE: Function return of type FILE

Probably you have a keyword without asterisk key?
That's why you have troubles with pointers in C++...
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close