Double argument question

This is a discussion on Double argument question within the C Programming forums, part of the General Programming Boards category; Code is too long to post so I will try to pose the problem in a simplified way. I am ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    84

    Double argument question

    Code is too long to post so I will try to pose the problem in a simplified way.

    I am dealing with epoch/unix time and read in these times from a file into a giant struct array. I assign these values as the data type double *time in the type definition.

    I go through and find the max and min epoch time and assign it to variables max and min of type definition double.

    Now, I am trying to pass this max and min into a function.

    Upon passing in the function as an argument, when I print the values out to check that the right ones are passed in - they appear way different. I figure my way would be sufficient way as all I want to do is pass-by-value and not pass by the reference, since max and min are not memory locations or used as pointers and I do not care what happens to them inside the function. The function just uses their info and moves on.

    Is this way not allowed?

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by towed View Post
    Code is too long to post so I will try to pose the problem in a simplified way.
    Try and write as short a program as you can replicating the problem. This will help to locate what kind of syntax-usage mistake you are making. What you are asking about certainly sounds fairly basic.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    84
    Well :-/ I am away from my work computer so I cannot write up a quick code.

    Essentially:

    Code:
    Headerfile:
    
    typedef struct{
    double *timeobs;
    } time
    
    int initialize(double max, double min);
    
    ----
    Sourcefile - main.c:
    
    int main(argc, argv){
    
    // Skip the i/o routines
    
    min = time->timeobs[0];
    max = time->timeobs[n-1];
    
    printf("%lf \n", max);
    
    initialize(max, min);
    
    return 0;
    }
    ----
    Sourcefile - function.c:
    
    int initialize(double max, double min)
    {
    
    printf("%lf \n", max); // Check to see if right value was passed in
    
    // Skip the innards of this code
    
    return 0;
    
    }
    The first print statement then prints correctly, while the second one does not but gives me rubbish.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Hmmm.
    Code:
    #include <stdio.h>
    
    void test (double a, double b) {
    	printf("%lf %lf\n",a,b);
    }
    
    int main(int argc, const char *argv[]) {
    	double x = 32.5, y = 101.01;
    	printf("%lf %lf\n",x,y);
    	test(x, y);
    	return 0;
    }
    [root~/C] gcc -Wall test.c
    [root~/C] ./a.out
    32.500000 101.010000
    32.500000 101.010000

    Does this clarify anything? It sounds like you have made some other kind of mistake you have not taken into account.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    84
    Well. It seems to be working now... :-/ Don't think I really did or changed anything?!?!

    :sigh:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions, have errors...NEED HELP FAST
    By alkamenes in forum C++ Programming
    Replies: 6
    Last Post: 11-02-2009, 02:00 PM
  2. Need some help...
    By darkconvoy in forum C Programming
    Replies: 32
    Last Post: 04-29-2008, 03:33 PM
  3. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM

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