Thread: referencing FILE pointer inside struct

  1. #1
    Registered User
    Join Date
    Mar 2008

    referencing FILE pointer inside struct


    I am trying to access a FILE *pointer and a pointer to a typedef, inside a struct.
    I also, maybe more importantly, need to access these two in a pointer to that type of struct.

    		typedef struct {
    			int dataSize;
    			int etc;
    		//this is where i am first confused
    			FILE *fp;
    		// second confusion with pointer to typedef struct
    			PreviouslyDefined *PDptr;
    			} fileptrstruct;
    i want to reference FILE *fp and PreviouslyDefined *PDptr

    i imagine it is some thing like:

    		fileptrstruct->FILE *fp 
    			// as in:   fileptrstruct->FILE *fp = *buffer ; ?
    			// and: foo(fileptrstruct *fp);
    	//and the second thing:
    		fileptrstruct-> PreviouslyDefined *PDptr;
    am i close? i hope my question is clear.

    thanks very much for help on this, and the help i've already received from reading around here.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    You would do something like this:
    fileptrstruct->fp = (something that is a FILE *)
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Mar 2008
    thank you for the almost immediate response.

    i will try to make this work then return my results.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    A struct is just a data type.
    You must create an instance of the type first and depending on if it's a pointer or if it's allocated on the stack, it becomes either "." or "->".
    Plus you access everything inside the struct by its name, not its type.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 02:24 PM
  2. Problems passing a file pointer to functions
    By smitchell in forum C Programming
    Replies: 4
    Last Post: 09-30-2008, 02:29 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Replies: 10
    Last Post: 05-18-2006, 11:23 PM
  5. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM