Thread: Passing data/pointers between functions

  1. #1
    Registered User
    Join Date
    Oct 2001

    Passing data/pointers between functions

    I have just started working with functions. I am trying to clarify how to pass data between these functions without declaring global variables. I am also trying to discover how to pass file pointers between functions.


    The code I attached below opnes 3 files. If I wanted to open these 3 files in a separte function (say will call it "open_files).

    In the stock_report function, I want to call the open files function. How do I pass the file pointer into the stock_report function so that I can use the open_files function?

    This progam has 2 input files but I could not figure out how to attach more than 1 file to this post.

    Thanks again as always,

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    I have a great function you can use to open file! It's called, conveniently enough, "fopen()"! It works wonders. Alternately, at a bit more low level, you could just call "open"...

    How to pass a file pointer:

    void myfun( FILE *fp )
    { stuff...

    Called like:

    myfun( myFilePointer );

    How to return a file pointer:

    FILE *myfun( ...something or nothing... )
    { stuff...

    Called like:

    fp = myfun( ...something or nothing... );

    What's not to know?


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing from functions in classes to another function in another class?
    By Robert_Sitter in forum Windows Programming
    Replies: 1
    Last Post: 12-13-2005, 07:46 AM
  2. passing 2dimensional arrays to functions
    By owi_just in forum C Programming
    Replies: 1
    Last Post: 04-25-2005, 08:08 AM
  3. passing structures to functions
    By AmazingRando in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2003, 11:22 AM
  4. Passing structures between functions
    By TankCDR in forum C++ Programming
    Replies: 2
    Last Post: 01-29-2002, 10:54 AM
  5. Replies: 1
    Last Post: 01-20-2002, 11:50 AM