referencing FILE pointer inside struct

This is a discussion on referencing FILE pointer inside struct within the C Programming forums, part of the General Programming Boards category; hello. I am trying to access a FILE *pointer and a pointer to a typedef, inside a struct. I also, ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    2

    referencing FILE pointer inside struct

    hello.

    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.


    Code:
    		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:

    Code:
    		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
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You would do something like this:
    Code:
    fileptrstruct->fp = (something that is a FILE *)
    --
    Mats
    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
    Posts
    2
    thank you for the almost immediate response.

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

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,184
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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, 01: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

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