How can I set a file pointer to zero? Casting?

This is a discussion on How can I set a file pointer to zero? Casting? within the C Programming forums, part of the General Programming Boards category; I want to initialize my FILE* fp (file pointer) to zero. Which is a data member of my class. 17 ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    93

    How can I set a file pointer to zero? Casting?

    I want to initialize my FILE* fp (file pointer) to zero. Which is a data member of my class.

    17 invalid conversion from `int' to `FILE*'

    in my header

    const void setFileP(int m){ fp = m; } //Sets FP to an integer


    and in my class


    Code:
    void Bank::init(int n, int m)
    {
         setSize(n);
         setFileP(m);
    }
    Last edited by INFERNO2K; 07-04-2005 at 01:15 PM.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    FILE is a structure, I think.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Sorry Im using some C++ here but I am using stdio librarys

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    Okay, try this:
    Code:
    FILE *fp;
    fp = 0;
    I think it sould work. You probably went
    Code:
    FILE *fp;
    *fp = 0;
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    93
    Didnt work, that's what I have originally

    fp = m

    where I send in 0 to that function

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Why are you posting this on the C board? classes are not C. They're C++. Wrong forum.

    Next, why are you trying to manipulate the file pointer manually? You set pointers to NULL or to something specific by a call to fopen etc. You don't dereference the file pointer, because it's obvious you don't know anything about its contents. Set it to NULL and leave it at that. You shouldn't even have a function to set it to anything, let alone an integer. FILE* are not integers. Don't try to use them as one.


    Quzah.
    Hope is the first step on the road to disappointment.

  7. #7
    I typecast anyway.
    Join Date
    Jun 2005
    Posts
    25
    I agree, it's very unclear what you're trying to do. Perhaps you were looking for something like rewind?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  4. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21