Thread: Passing parameters to a module

  1. #16
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    OK - here we go -
    I have a call to the function
    collectstat(fp);

    Code:
    ???? collectstat(FILE *fp, name_type in_file) {
                    if (access(in_file,0) == 0) {
                    stat(in_file, &file_info); }
                    return(file_info); }
                    }
    }
    If I stat the file into the struct stat file_info - what is the syntax to return the struct and then later to pass it to another function?

    I made the struct "static" - hoping it would be there on my return - but it is not - so I will have to pass it back to the calling pgm and then later into the writedata function.

    Thanks
    Sue

  2. #17
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    struct stat collectstat(FILE *fp, name_type in_file) 
    {
      if (access(in_file,0) == 0) {
        stat(in_file, &file_info); 
      }
      return(file_info); 
    }
    -Prelude
    My best code is written with the delete key.

  3. #18
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    Interesting that my stat'd file_info (even though) a static - does not remain between calls....

    I am trying to confirm that that is the case -

    however, can you please confirm -

    in the module filebinaryopen I return a *fp1 -

    in the calling pgm I have
    fp = filebinaryopen(argv[1])

    will that pass fp1 to fp - so that later in my calling pgm if I access fp I will get the pointer to the opened pgm? or am I accessing pointers of pointers????

    sue

  4. #19
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >in the module filebinaryopen I return a *fp1 -
    >in the calling pgm I have
    >fp = filebinaryopen(argv[1])
    This doesn't sound right if you are dereferencing fp1 when you return it. If fp and fp1 are both FILE *'s then there's no need to dereference fp1 when returning it unless you declare filebinaryopen to return a FILE **.

    >so that later in my calling pgm if I access fp I will get the pointer to the opened pgm?
    Yes, it assigns the opened stream to fp so that when fp1 goes out of scope the stream still can be accessed.

    >or am I accessing pointers of pointers?
    Not unless you are doing so by design or by accident. As it is you aren't.

    -Prelude
    My best code is written with the delete key.

  5. #20
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    it must be getting late - i am babbling....

    I have altered the fp to an fp1 (see last note)

    I am now attemping to read the output'd binary file into the 2nd pgm - I have opened the file via the module (all seems ok) - however, when I try to read it -

    Code:
     while ( fread(&in_file_record, sizeof(file_sig), 1, fp1) == 1) {
    it doesn't get inside the while look - and no errors are displayed to help...I have confirmed that it is getting to the point immediately before this line...

    and not to immediately after....
    The call to the filebinaryopen in the module make the mode "rwb"
    Is that correct?

    sue

  6. #21
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >The call to the filebinaryopen in the module make the mode "rwb"
    That's not valid by ANSI C, whether it works or not is implementation dependent. "r+b" should work a bit better if you want to preserve the contents of the file.

    >I have confirmed that it is getting to the point immediately before this line
    Could you post a skeleton program that does all of this so that we can debug more easily? Trying to find a problem with little snippets that aren't being executed is difficult.

    -Prelude
    My best code is written with the delete key.

  7. #22
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    HA HA HA HA (much hysterical laughter!!!)

    I think it is working!!

    I have passed the file mode (as a char array of 2) to the modules - and used that during the file opens.

    It seems to be acceptable.


    thanks so very much to you and hammer for your patience - a truly steep learning curve - but worth the outcome.

    Thanks again!!!

    Sue

  8. #23
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    "Sue", you are making things more difficult than necessary!

    You are trying to "simplify" things by avoiding passing parameters.

    Perhaps you should perfect a fully parameterized solution first! Then you can, step by step, eliminate redundant arguments.

    As is, your programming is a tired mess!

    (1)Figure out what you want to do in psuedocode first.

    (2)Write out the program/functions in small chunks

    (3) Debug

    (4) Go back to (2)

    Sorry for being so critical, but you should know better than to let the code get out of hand like that....
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #24
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59
    that was nice
    " programming is 1% syntax and 99% logic "

  10. #25
    Registered User
    Join Date
    Apr 2002
    Posts
    32
    Thanks for the critique - sebastiani - actually I am not trying to simplify anything - just trying to learn the syntax for passing parameters as pointers - and when it is appropriate to do so - as is stands your comments are redundant to my learning curve at this point in time.....but thanks for the interest and the lecture....

    I will bear it in mind.

    Sue

  11. #26
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Nicely put !
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 01:08 PM
  2. Replies: 7
    Last Post: 04-19-2006, 11:17 AM
  3. Passing parameters to modal dialogs
    By Halloko in forum Windows Programming
    Replies: 2
    Last Post: 10-11-2005, 07:15 AM
  4. Passing parameters from VB to C++ through ActiveX DLL
    By torbjorn in forum Windows Programming
    Replies: 0
    Last Post: 12-10-2002, 03:13 AM
  5. Function basics
    By sjleonard in forum C++ Programming
    Replies: 15
    Last Post: 11-21-2001, 12:02 PM